[英]Many to many relationship events with backbone.js
I have a many-to-many relationship with two of my backbone.js models implemented using a pivot table on the serverside. 我与使用服务器端的数据透视表实现的两个bone.js模型具有多对多关系。 I'm trying to figure out how to structure it clientside. 我试图弄清楚如何在客户端构建它。 My current structure is: 我当前的结构是:
1) I have a Tag model, and a TagView which renders a checkbox and the tag label, I have a checked event on the checkbox which does nothing at the moment. 1)我有一个Tag模型,还有一个TagView和一个呈现复选框和标签标签的TagView,我在复选框上有一个checked事件,该事件目前不起作用。
View is only for visual display of model. 视图仅用于模型的可视化显示。 Please specify the need for TagsCollectionView in more details: 请更详细地指定对TagsCollectionView的需求:
I can not provide the whole design due to lack of requirement details. 由于缺少需求细节,我无法提供整个设计。 but, I think below code should trigger the starting point of your design. 但是,我认为下面的代码应该触发设计的起点。
var TagsCollectionView=Backbone.View.extend({
el:$(),
});
var Tag=Backbone.Model.extend({
defaults:{
// define the 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 to render the checkbox and label
},
customFunction:function(){
// whatever you want to do after checking event of checkbox
}
});
// collection to collect all the tags
var TagCollection=Backbone.Collection.extend({
model:Tag
});
var Notes=Backbone.Model.extend({
defaults:{
'tagCollection':TagCollection
}
});
// you do not require TagsCollectionView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.