jewelwast
jewelwast

Reputation: 2777

underscore js backbone js two templates

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

Answers (2)

arhea
arhea

Reputation: 454

The proper syntax would be

var data = {
    modelOne: model.toJSON(),
    modelTwo: model2.toJSON()
}

that.$el.html(_.template(tmpl, data));

Upvotes: 1

Ulug'bek
Ulug'bek

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

Related Questions