Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有什么方法可以从控制器中获取模型?我需要调用模型上定义的实例方法和
this.get(methodName)(params)
不起作用,因为它丢失了被调用函数中的“this”调用上下文。
谢谢你。
我不确定你想在方法中存在哪个上下文,如果你需要切换上下文,你可以使用调用/应用。上下文应该是方法的上下文,而不是 javascript 标准的控制器。
var model = this.get('model'); model.methodName(arg1, arg2);
model.methodName.apply(this, arrayOfArgs); model.methodName.call(this, arg1, arg2);