访问嵌套的骨干示范从胡子模板的属性 [英] Access Nested Backbone Model Attributes from Mustache Template

查看:160
本文介绍了访问嵌套的骨干示范从胡子模板的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有那就是另一骨干模型的引用的属性的一个骨干网的模式。例如,一个人有一个地址对象的引用。

I have one Backbone model which has an attribute that is a reference to another Backbone model. For example, a Person has a reference to an Address object.

Person
  FirstName
  LastName
  Address
    Street
    City
    State
    Zip

这是扩展骨干模型类。所以,后来我要是像构建如下的对象.​​..

These are classes that extend the Backbone model. So, then if I construct an object like the following...

var address = new Address({ Street: "123 Main", City: "Austin" });
var person = new Person({ FirstName: "John", Address: address });

我似乎无法弄清楚如何获得它在我的胡子模板。

I cannot seem to figure out how to access it in my Mustache template.

Hi {{FirstName}}, you live in {{Address.City}}.

显然是行不通的。当我看到在Firebug的内部,地址是一个对象,但城市是地址的属性对象中的一个属性。我无法找到如何访问相关对象的这些属性的例子。

Obviously does not work. When I look at the internals in Firebug, Address is an object, but the City is an attribute within the attributes object of Address. I cannot find any examples of how to access these attributes of associated objects.

我AP preciate任何帮助!谢谢!

I appreciate any help! Thanks!

推荐答案

请尝试使用把手,模板引擎的基础上胡子嵌套属性的支持。

Try using Handlebars, a templating engine based on Mustache with nested properties support.

然后,它会像容易{{地址/城市}}

如果你不想改变你的模板引擎,您可以拼合从结果地址对象,并通过他们为直接在人物的属性

If you don't want to change your templating engine, you can flatten results from Address object and pass them as properties directly on the Person.

这篇关于访问嵌套的骨干示范从胡子模板的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆