[英]Passing model to Backbone View in object literal
我不确定是否可以,但是我想将参数传递给对象文字中的函数。
这是我的对象:
var object_literal = {
"thing" : new APP.SomeView({ model : model_to_pass, secondPart : static_model})
};
然后我想遍历一个集合,获取一个参考
someCollection.each(function(things) {
//will equal "thing"
var x = things.get("reference");
//Then do something like this (which obviously won't work)
layout.someRegion.show(object_literal[x](model_to_pass))
}
如您所见,“事物”是一个函数(在本例中为主视图)。 我想传递“事物”参数(“ model_to_pass”)。 如何才能做到这一点?
如果使它更容易,我将使用骨干,下划线和jquery(如果它们提供了更好的解决方案)。
我认为这对于解决方案来说有点过分设计,而使用条件条件将是最好的方法。
someCollection.each(function(things) {
//will equal "thing"
var x = things.get("reference");
if (x === "thing") {
new APP.SomeView({ model : model_to_pass, secondPart : static_model}
}
}
谢谢你们每一个人的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.