0

当我尝试将条目变量从一个视图传递到另一个视图时,我得到条目在第二个视图中未定义。

这是我的帖子查看

append_post: function(post){        
    view = new Stream.Views.PostEntry({entry: post});
    $("#stream-bank").append(view.render().el);
}

这是我的帖子条目视图

Stream.Views.PostEntry = Backbone.View.extend({

  template: JST['streams/post'],

  render: function(){
    console.log(entry); // Error: 'entry is not defined' 
    this.$el.html(this.template({post: entry}));
    return this;
  }
});
4

1 回答 1

1

Backbone 通过将它们分配给 this 的属性来处理构造函数的一些参数(有关详细信息,请参阅 View#initialize),其余的进入 this.options。- mu 太短了

render: function(){
    console.log(this.options.entry); //  
    this.$el.html(this.template({post: this.options.entry}));
    return this;
}
于 2013-06-04T06:00:38.537 回答