javascript - Many to many relationship events with backbone.js -
javascript - Many to many relationship events with backbone.js -
i have many-to-many relationship 2 of backbone.js models implemented using pivot table on serverside. i'm trying figure out how construction clientside. current construction is: 1) have tag model, , tagview renders checkbox , tag label, have checked event on checkbox nil @ moment.
i have tagscollection, holds bunch of tags. i have tagscollectionview, binds add, reset etc of tagscollection, , adds tagviews added tags, renders them, , appends html current html (on reset, html reset). i have global tagcollection instance contains possible tags i have notes model contains (empty) tagcollection called selectedtags on init. the server returns array of selected tagids each notes, add together tagcollection. now comes hard part, tying together.. notesview has own tagscollectionview bound global tagscollection (so can list tags).. now, how checked event on checkedbox of sub tagviews trigger add together this notes model's selectedtags? should provide reference notes model instance tagscollectionview on init provides tagviews creates, checked event adds/removes items model? that's best way can figure out how this, other thoughts appreciated.
view visual display of model. please specify need tagscollectionview in more details:
use alter event checking checkbox. i advise incremental coding. first work tag , tagview, works, go on adding collection hold tags. after can add together notes. it's 'divide , conquer' :) don't confuse whole design, simple when start.i can not provide whole design due lack of requirement details. but, think below code should trigger starting point of design.
var tagscollectionview=backbone.view.extend({ el:$(), }); var tag=backbone.model.extend({ defaults:{ // define default properties } }); var tagview=backbone.view.extend({ el:$("body"), events:{ 'change #checkbox':'customfunction' }, initialize: function(){ _.bindall(this, 'render','customfunction'); this.render(); }, render:function(){ var tag=new tag(); // code render checkbox , label }, customfunction:function(){ // whatever want after checking event of checkbox } }); // collection collect tags var tagcollection=backbone.collection.extend({ model:tag }); var notes=backbone.model.extend({ defaults:{ 'tagcollection':tagcollection } }); // not require tagscollectionview
javascript ajax backbone.js many-to-many rich-internet-application
Comments
Post a Comment