backbone.js每个函数都没有接收模型

时间:2013-01-21 10:08:27

标签: backbone.js

我正在尝试接收json数据并附加到元素。所有工作都很好,我使用静态分配。当我开始从服务器端获取数据,或者使用fetch对我来说没有任何工作..我的fech过程有问题,任何可以帮助我纠正我的获取过程并更新我的代码。(而不是简单地放置正确的代码) ..

我的JSON(样本):

nameing = [
    {name:'student4'},
    {name:'student5'},
    {name:'student6'}
]

骨干代码:

(function($){

var list = {};

list.model = Backbone.Model.extend({
  defaults:{
    name:'need the name'
  }
});



list.collect = Backbone.Collection.extend({
  model:list.model,
  url : 'data/names.json', //this is correct path.
  initialize:function(){
    this.fetch();
  }
});


list.view = Backbone.View.extend({
  initialize:function(){
    this.collection = new list.collect();
    this.collection.on("reset", this.render, this);
  },
  render:function(){
    _.each(this.collection.models, function(data){
      console.log(data); // i am not get any model here... any one correct my code?  
    })
  }
});

var newView = new list.view();


})(jQuery)

提前感谢。

1 个答案:

答案 0 :(得分:1)

您的JSON无效。 Wiki

[
  {"name":"student4"},
  {"name":"student5"},
  {"name":"student6"}
]