我想使用 render() 渲染模板并希望传递一些数据(模型)
如果我将参数作为模型传递,我会在模板中获取数据 模型: this.controllerFor(this.routeName).someModel
this.render('my-template', {
into: 'application',
outlet: 'myOutlet',
model: this.controllerFor(this.routeName).someModel
});
但是下面的方法不起作用。传递的模型的命名是否有一些限制?
this.render('my-template', {
into: 'application',
outlet: 'flyout',
myModel: this.controllerFor(this.routeName).someModel
});
最佳答案
您传递的属性不是您的模型
的名称,而是您的模型
。
无论您作为 model
属性传递什么内容,都将被设置为相应 Controller 上的 model
属性。
ember所做的相关检查under the hood of render()如下:
if (options && options.model) {
controller.set('model', options.model);
}
其中 options 是作为第二个参数传递给 render()
的内容。
值得注意的一件事是,这只是将 controller.model
设置为 controller.someModel
,这是多余的,因为您已经可以访问此数据。
关于javascript - Ember 使用 this.render 将数据传递到模板时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39912852/