如何将选项传递给Marionette中的ItemView?

时间:2015-06-03 09:11:59

标签: backbone.js marionette

我使用Marionette,我想将一些变量传递给ItemView。我尝试按照此处的说明操作:http://marionettejs.com/docs/v2.4.1/marionette.functions.html#marionettegetoption 但它不起作用。我的代码是:

module.exports = function(p_hash) {
    var TreeView = Marionette.ItemView.extend({
        template: '#tree',
        initialize: function(attributes, options) {
            if (options.type == "organizations") {
                ...
            }
        }
    });
    return new TreeView(); 
}; 
... 
var organizations_tree = new TreeView({}, {type: "organizations", two_levels: false});

我的选项在初始化方法中未定义。

我可能会错过一些非常简单的事情。

你有什么想法吗?

谢谢Alex A。

1 个答案:

答案 0 :(得分:-1)

视图的初始化方法应该只包含1个参数。

例如:

initialize: function(options) {

}

您正在考虑一个Backbone.Model,它有2个参数:

initialize: function(attributes, options) {

}