this might be a simple question, but I've spent some time with it and I can't figure out what to do.
I've got a Backbone model and I'm trying to pass myData as an argument to MyModels in namedAttributes. Bind doesn't really help, since "this" is the context of namedAttributes, not RS.Models.MyModel.
Any suggestions?
RS.Models.MyModel = Backbone.Model.extend({
myData: {},
namedAttributes: {
"collection": _.bind(function(attrs) {
// "this" is the wrong context. How do I access myData from here?
var options = {myData: this.myData};
return new RS.Models.MyModels(attrs, options)
}, this)
},
initialize: function(attributes, options) {
if (options && options.columnData) {
this.myData = options.myData;
}
},
});
initialize, the object is already done. Inside that_.bind()call, which will be made during the process of assembling the larger object you're passing to Backbone, that larger object is still "under construction".