0
我有2個型號爲創建綁定多個模型在骨幹網的單一視圖
var Info = Backbone.Model.extend({
defaults: {
name: '',
company: ''
},
initialize: function(){
console.log('Object of type Info created');
},
});
var Emp = Backbone.Model.extend({
defaults: {
empId: '',
empGroup: ''
},
initialize: function(){
console.log('Object of type Emp created');
}
});
查看
var model = new Info();
model.set({
name: 'John',
company: 'ABC'
});
model.bind('change', function(){
model.save();
});
model.trigger('change');
var ViewClass = Backbone.View.extend({
_modelBinder: undefined,
initialize: function(){
this._modelBinder = new Backbone.ModelBinder();
this.render();
},
render: function(){
var template = _.template($('#App1').html());
this.$el.html(template);
var bindings = {
name: '[name=name]',
empId: '[name=empId]'
};
this._modelBinder.bind(model, this.el, bindings); // this will bind for Info.
}
});
HTML:
<script type="text/template" id="App1">
<div id="wrapper">
Name: <input type="text" name="name" /><br />
EmpId: <input type="text" name="empId" />
</div>
</script>
我們如何可以綁定兩個信息和僱員模型?