解析Backbone.js手柄[对象]
对handlbar.js来说比较新,但在我尝试访问嵌套属性之前,我的#每个都是功能性的。特别是author.name解析Backbone.js手柄[对象],backbone.js,handlebars.js,Backbone.js,Handlebars.js,对handlbar.js来说比较新,但在我尝试访问嵌套属性之前,我的#每个都是功能性的。特别是author.name <!-- Handlebars.js Blog Template --> <script id="posts-tpl" type="text/x-handlebars-template"> {{#each post}} <div class="blog-post"> <h2 class="blog-post-title">&
<!-- Handlebars.js Blog Template -->
<script id="posts-tpl" type="text/x-handlebars-template">
{{#each post}}
<div class="blog-post">
<h2 class="blog-post-title"><a href="#">{{title}}</a></h2>
<p class="blog-post-meta">{{author.name}}</p>
<div>{{{body}}}</div>
</div>
{{/each}}
</script>
我在上有一个完整的示例,如果您查看一下要传递到模板中的内容,就会看到问题所在 在
render
函数中,尝试检查this.collection.toJSON()的内容代码>实际上是
基本上,它看起来是这样的:
[
{
author: {
__type: "pointer",
className: "_User",
objectId: "JCAjG1AIN0"
},
title: "WTFBBQ",
body: "<p><h3>test</h3> egg on face. This cannot be good. </p>"
}
]
我不熟悉parse.js,所以这可能不是最好的解决方案,但它应该可以工作对不起,问题是什么?为此道歉。author.name属性没有呈现-我没有返回我认为是的数据。谢谢。我将不得不查看我的解析查询,其中author作为指向用户“table”的指针仍然存在,我看到了这个。集合看起来就像您所说的,但是当页面在Chrome中呈现时,JavaScript控制台允许我展开“author”看看我想要的属性:/我错过了一些我不完全理解的“简单”的东西。你搞定了。功能齐全。它在指定的索引处将其从集合中拉出,然后执行我丢失的.get()。谢谢你!
[
{
author: {
__type: "pointer",
className: "_User",
objectId: "JCAjG1AIN0"
},
title: "WTFBBQ",
body: "<p><h3>test</h3> egg on face. This cannot be good. </p>"
}
]
var collection = { post: this.collection.toJSON() };
for (var i=0; i<collection.post.length; i++) {
if (collection.post[i].author) {
collection.post[i].author = this.collection.at(i).get('author').toJSON();
}
}