Handlebars在#each上解析错误

big*_*olf 7 javascript jquery handlebars.js

我正在返回以下JSON对象

{"status":"success",
"valmessage":"Your message has been sent successfully.",
"postcontent":{
    "post_author":1,
    "post_recipient":"1",
    "post_title":"handle test 2",
    "post_type":"wp_inbox_msg",
    "post_content":"<p>giving it another go.<\/p>\n"},
"postmeta":{
    "postid":410,
    "postdate":"Monday, March 17th, 2014",
    "author":"admin"},"replies":null,
    "Formerrors":[]
}
Run Code Online (Sandbox Code Playgroud)

我在我的车把模板中收到以下错误:

Uncaught Error: Parse error on line 23:
...replies}}                    {{ #each replies }
----------------------^
Expecting 'ID', 'DATA', got 'INVALID' 
Run Code Online (Sandbox Code Playgroud)

在我的tempalte里面,我正在做以下事情:

        {{#if replies}}
                {{ #each replies }}
                    <li>
                        <figure class="reply-author-img">
                            <img alt="" src="{{ avatar }}" height="96" width="96">
                        </figure>
                        <div class="replycontentwrap">
                            <div class="reply-from">
                                <p class="reply-author">
                                    <strong>{{ fullname }}</strong>
                                    <span>{{ nickname }}</span>
                                </p>
                                <span class="replydate">{{ reply_date }}</span>
                            </div>
                            <div class="reply-content">{{ reply_content }}</div>
                        </div>
                    </li>
                {{ /each }}
            {{/if}}
Run Code Online (Sandbox Code Playgroud)

回复当前是空的,但是当回复消息时它应该返回一组对象,1)最好的方法1)使这个工作和2)使用handlebars.js处理这种数据结构?

764*_*484 23

你得到的错误是因为你在'#each'和'/ each'之前有一个空格,所以要做到:

{{#each replies}}
    /* each stuff */
{{/each}}
Run Code Online (Sandbox Code Playgroud)