Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
Backbone.js 渲染模型数组_Backbone.js_Rendering_Fetch - Fatal编程技术网

Backbone.js 渲染模型数组

Backbone.js 渲染模型数组,backbone.js,rendering,fetch,Backbone.js,Rendering,Fetch,嗨,我正在服务器上搜索一个特定的模式,我得到了一个模型列表 {"0":{"id":"20","name":"The White Tiger ","author":"Arvind Adiga","status":"Read"}, "1":{"id":"23","name":"Tiger and the Apes","author":"Benny Rice", "status":"Read"} } 我最初试图通过 var books = new Books() //Book

嗨,我正在服务器上搜索一个特定的模式,我得到了一个模型列表

 {"0":{"id":"20","name":"The White Tiger ","author":"Arvind Adiga","status":"Read"},
  "1":{"id":"23","name":"Tiger and the Apes","author":"Benny Rice", "status":"Read"} }
我最初试图通过

       var books = new Books()   //Books() is a collection name. 
       books.fetch({data: {name:'tiger'}});  
但这是一个未定义的错误

所以我试图得到一系列的模型

   var books = new Book() //Book is a model name
    books.fetch({data: {name:'tiger'}});   
我得到了上面提到的模型数组


如何在下划线模板中呈现模型数组?这真的是一种非常糟糕的做法吗?

您的收集响应不正确,这就是主干无法正确解析它的原因

如果要
fetch
ing一个集合,则其格式应为:

[{..},{..},{..}…]
对象数组

如果您正在
提取
模型,则他们应:

{..}
单对象哈希

因此,如果您修复了响应,那么它将自动加载到集合中,即

[ 
   {"id":"20","name":"The White Tiger ","author":"Arvind Adiga","status":"Read"},
   {"id":"23","name":"Tiger and the Apes","author":"Benny Rice", "status":"Read"} 
]