backbone.js - Backbone Nested Views & Nested Models -


i newbie backbone , trying start using in our projects.

my requirement have this

var textfields = backbone.model.extend({});  var textfieldscollection = backbone.collection.extend({});  var module = backbone.model.extend({      defaults: {         fields: new textfieldscollection() });  var modulecollection = backbone.collection.extend({      model: ctmodule }); 

now have views defined textfields & modules. if change value in textfields event gets fired model , changing value in model collection not getting updated. tried trigger backbone events in child model @ collection view not able map correct model triggered change event.

any comments helpful. not in position use more libraries. can done in backbone?

i not know full code, if in fashion backbone apps written should work.

quick tutorial:

var testmodel = backbone.model.extend({}); var testmodelcollection = backbone.collection.extend({ model: testmodel });  // if have view collection var testmodelcollectionview = backbone.view.extend({   initialize: function(opts) {     this.collection = opts.collection;     this.collection.on('change', this.render, this) // - rerender whole view    } });  //execution:     var modeldata = { foo: 'bar' }; var collection = new testmodelcollection([modeldata]);  var view = new testmodelcollectionview({collection: collection}); view.render();  collection.first().set('your_attr', 'new_value'); // cause rerender of view 

//////

one more thing - if have collection, kept model (in case modules model, have collection 1 of attributes), , view keeps model, have either bind directly view collection via model (this.model.get('fields').on( .... )), or rethrow collection event in model

i hope helped @ least bit.

//////

there might syntax errors in code - didn't run on js fiddle.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -