Reputation: 2777
I want to handle two templates in backbone js. How do I go about doing so? I want to pass in the json for the models in the template?
I have the following:
var json = model.toJSON(), json2 = model2.toJSON();
that.$el.html(_.template(tmpl, json, json2));
but that does not allow me to get the fields from the second json in underscore.
Upvotes: 0
Views: 93
Reputation: 454
The proper syntax would be
var data = {
modelOne: model.toJSON(),
modelTwo: model2.toJSON()
}
that.$el.html(_.template(tmpl, data));
Upvotes: 1
Reputation: 2832
If the models don't mixed inside template, You can do that : need to create new template for second model, and add to necessary address
var addressToSecondModel = $(that.$el).find("address");
addressToSecondModel.html(_.template(tmpl2, json2));
Upvotes: 0