在视图主干中传递模型

时间:2014-04-07 19:48:51

标签: backbone.js

嗨,我在路由器中有这个功能:

  home: function() {
 var attore= new Attore();
 var page = new ListPostView({
 model: this.attore
 });
    this.changePage(page);

  },

和模型Attore是:

var Attore = Backbone.Model.extend({

defaults: {
"nome":  "caesar salad",
"cognome": "ravioli"

},



});


 return Attore;
 });

但是发生了一个错误,告诉我模型在视图中未定义:

var ListPostView = Backbone.View.extend({

    tagName: "ul",
    id: "list",

    template: Handlebars.compile(template),

    initialize: function () {
        console.log(attore);
      this.model.bind("reset", this.render, this);
    },

    render: function (eventName) {
      $(this.el).empty();
      _.each(this.model.models, function (ad) {
        $(this.el).append(new SinglePostView({
          model: ad
        }).render().el);
      }, this);
      return this;
    }
  });

return ListPostView;

 });  

0 个答案:

没有答案