我一直試圖在一個視圖中顯示兩個模型。這裏是我的代碼:模板骨幹中的兩個模型查看
var self=this;
var aboutus=new Aboutus({id:1});
var company= new Company({id:1});
aboutus.fetch();
company.fetch();
var model = new Backbone.Model();
model.set({aboutus: aboutus, company: company});
var aboutusView=new AboutusView({model:aboutus,model2:company});
aboutusView.render();
self.changePage(aboutusView);
=======================
For Aboutus View Part:
var AboutusView = Backbone.View.extend({
template: _.template(aboutusViewTemplate),
initialize: function() {
_.bindAll(this, 'render');
},
render: function(){
console.log(this.model);
console.log(this.options.model2);
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
return AboutusView;
============================
In console log of this.model (aboutus) is:
===========================
child {attributes: Object, _escapedAttributes: Object, cid: "c0", changed: Object, _silent: Object…}
_changing: false
_escapedAttributes: Object
_pending: Object
_previousAttributes: Object
_silent: Object
attributes: Object
aboutusId: 1
description: "testing"
id: 1
imageExtension: ""
title: "ABOUT US"
__proto__: Object
changed: Object
cid: "c0"
id: 1
__proto__: ctor
所以,問題是我想顯示關於我們的aboutusId屬性,例如,描述:
在路由器本部獲取的機型關於我們和公司,並將它們添加到AboutusView 。我怎樣才能做到這一點?
哪裏是aboutusViewTemplate – 2014-01-22 13:05:27
@eguneys aboutusViewTemplate的定義僅僅是HTML模板展示數據。 – JaRoi