Collection prototype


#1

Hello, I have a field that is a reference to another model…

  costumerId:{
type:String,
optional:true,    
autoform: {
    type: "select2",
    options: function () {
        return Costumer.find().map(function (c) {
            return {label: c.name, value: c._id};
        });
    }
}  

as you can see, im using a function to populate the options… this function is used in many places, so i would like to attach a function to my Costumer collection… so I could use Costumer.quickList() to get this list…
how can i do that?


#3

I don’t understand, whats the problem with my post?


#4

(responded too fast, thank you ahref)


#5

I withdrew my post, which leaves that message because I tried to answer your question without reading it. It doesnt refer to your topic.

However I shall try to answer it now:

You should be able to store that query in the Collection object.

 Costumer.quickList = function() {
    //stuff
    };

Or throw the function inside another object.

App.Forms.customerQuickList = function() {
}

@vjau that isn’t quite what they are asking.

They want to call a method located on the collection that returns the result of that function, the mapped list. With your transform they’d still need a function which maps the .find() to an array of result.quickLists. I hope that makes sense.


#6

Wow, so simple! thanks!!