【发布时间】:2013-08-22 21:28:50
【问题描述】:
我正在使用带有嵌套模型的主干.js。这个想法是自包含作者的所有属性以及在帖子和 cmets 上重用作者模型。至少在理论上我认为这是有道理的。
但是,像这样进行设置时,我对如何使用 Handlebars 检索不同的值感到困惑。 Handlebars 不喜欢从我读过的内容中传递对象。我可以很容易地用{{status}} 检索{{#each}} 中的状态,但很自然地做{{author.name}} 是行不通的。
我已经研究过使用 Helper,但是正如您所见,我在其中嵌套了 cmets,其中将嵌套另一个作者。我不相信 helpers 里面的 helpers 会起作用。
这是从 Chrome 控制台中提取的示例对象。
Object {items: Array[2]}
+items: Array[2]
+0: Object
+author: child
_changing: false
_pending: false
_previousAttributes: Object
+attributes: Object
name: "Amy Pond"
profileImage: "Amy.jpg"
__proto__: Object
changed: Object
cid: "c0"
__proto__: Surrogate
comments: child
id: "50f5f5d4014e045f000001"
status: "1- This is a sample message."
__proto__: Object
+1: Object
author: child
comments: child
id: "50f5f5d4014e045f000002"
status: "2- This is another sample message."
__proto__: Object
length: 2
__proto__: Array[0]
__proto__: Object
我在我的组织中是不正确的,还是有更好的方法来处理多维数据?或者有没有让 Handlebars 获得每个值的好方法?
如果有更强大的模板引擎,我愿意选择。
【问题讨论】:
标签: backbone.js handlebars.js template-engine javascript-objects