Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在车把中的对象数组上迭代无效_Javascript_Json_Handlebars.js - Fatal编程技术网

Javascript 在车把中的对象数组上迭代无效

Javascript 在车把中的对象数组上迭代无效,javascript,json,handlebars.js,Javascript,Json,Handlebars.js,因此,我试图迭代一个由服务器作为json对象返回的数组。我已经做过一次了,效果很好,但这里的另一个似乎不起作用 车把代码是这样的 <script id="messageTemplate" type="text/x-handlebars-template"> {{#each response.data}} <div class="message"> {{#messages}} <h4>{{this.from}}</h4> <b&

因此,我试图迭代一个由服务器作为json对象返回的数组。我已经做过一次了,效果很好,但这里的另一个似乎不起作用

车把代码是这样的

  <script id="messageTemplate" type="text/x-handlebars-template">
{{#each response.data}}
<div class="message">
  {{#messages}}
  <h4>{{this.from}}</h4>
  <b>{{this.datetime}}</b>
  <p>{{this.body}}</p>
  {{/messages}}
</div>
{{/each}}
</script>
 {
 "data": {
"id": 32607158,
"with_account": "user1",
"with_account_id": 8483786,
"last_message_preview": "XD",
"message_count": 289,
"messages": [{
  "id": 153359194,
  "from": "user1",
  "account_id": 20094939,
  "sender_id": 8483786,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711004
}, {
  "id": 153359270,
  "from": "user2",
  "account_id": 20094939,
  "sender_id": 20094939,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711023
}, {
  "id": 153359330,
  "from": "user1",
  "account_id": 20094939,
  "sender_id": 8483786,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711044
}, {
  "id": 153359334,
  "from": "user2",
  "account_id": 20094939,
  "sender_id": 20094939,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711048
}, {
  "id": 153359386,
  "from": "user1",
  "account_id": 20094939,
  "sender_id": 8483786,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711057
}, {
  "id": 153359430,
  "from": "user2",
  "account_id": 20094939,
  "sender_id": 20094939,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711065
}, {
  "id": 153359474,
  "from": "user1",
  "account_id": 20094939,
  "sender_id": 8483786,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711078
}, {
  "id": 153359522,
  "from": "user2",
  "account_id": 20094939,
  "sender_id": 20094939,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711090
}, {
  "id": 153359638,
  "from": "user2",
  "account_id": 20094939,
  "sender_id": 8483786,
  "body": "*hugs*",
  "conversation_id": 32607158,
  "datetime": 1439711106
}],
"done": false,
"page": 2,
"datetime": 1439711387
},
"success": true,
"status": 200
}

有人知道它为什么不起作用吗?提前感谢您的帮助。

您的
每个
都放错了位置<代码>数据
是单个对象,因此不需要迭代。对于
数据

                {{#with response.data}}
                <div class="message">
                    {{#each messages}}
                    <h4>{{this.from}}</h4>
                    <b>{{this.datetime}}</b>
                    <p>{{this.body}}</p>
                    {{/each}}
                </div>
                {{/with}}
{{#with data}}