jquery - How to save a group of selected Models from a CollectionView in backbone marionette -
i using backbone marionete framework , have situation this
here every row model , marionette collectionview holding collection of contacts. on click on submit button user can select many contacts wants , when click on submit have call on each model. best way it. first of not getting how it. in know how call save on single model. have searched couple of posts not providing solution. can me please.
what want, array of models selected user, can access models 1 one.
there 2 solutions problem. when onselect event triggered user, can either
1) nothing
2) save reference selected model
then, when onsubmit event happens, depending on chose above, have to
(1) parse html of each view in table, checking if 'checkbox' checked, , if so, access model via view's model
property
(2) or, since saved array references selected models, can iterate on said array
where code have reside?
since want access models rendered within marionette.collectionview, code needs reside in said marionette.collectionview, because there have access models.
if follow method (2), i.e. save reference selected model @ time of select event, code needs reside in marionette.itemview of respective model.
example solution (2)
var selectedmodels = []; var itemview = marionette.itemview.extend({ events: { 'click checkbox': function () { selectedmodels.push(this.model); } } }); var collectionview = marionette.collectionview.extend({ itemview: itemview, events: { 'click .submit': function () { _( selectedmodels ).invoke(somefunction); } } });
Comments
Post a Comment