Is it possible to create model and view in Backbone.js with parameters ?
I try simple like
var TestModel = Backbone.Model.extend( {
initialize: function(test){
this.set('test',test);
alert("test");
}
});
but I got message this.set is not a function.
There’s a syntax error in your example code, but that should work just fine. You also need to account for the model’s
attributesas the first parameter and reference a genericoptionsobject as the second parameter (see the code here http://backbonejs.org/docs/backbone.html#section-28 )From your sample code, though, it looks like you’re just trying to pass data to the model, which is handled for you automatically.
Or if you’re trying to get some options, you can do this: