I have been trying to display two models in one view. Here is my code:
On router part- fetch models of about us and company and add them to AboutusView:
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
So the question is I want to display aboutus attributes such as aboutusId, description in template. How can i do that?