【发布时间】:2015-04-30 09:46:17
【问题描述】:
我正在尝试根据我的路由接收到的操作设置模型值。
//app/routes/map.js
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return {
trail: null
};
},
actions: {
event: function(name, value) {
if (name === 'trail.selected') {
this.modelFor('map').set('trail', value);
}
}
}
});
当我尝试使用时
this.modelFor('map').set('trail', value);
我收到以下错误:
未捕获的类型错误:this.modelFor(...).set 不是函数
当我尝试使用时
this.modelFor('map').trail = value;
我得到了那个错误
未捕获的错误:断言失败:您必须使用 Ember.set() 将([object Object] 的)
trail属性设置为<nested-component@model:mtg-trail::ember617:kvdpo>。
编辑添加的模板
//app/templates/map.hbs
<h2>Trail's name: {{trail.name}}</h2>
{{#if trail}}
{{map-draw trail=trail.id}}
{{/if}}
【问题讨论】:
-
地图路线加载了吗?即它是同一层次结构中的父级吗?如果不是,您将无法以这种方式设置它
-
我不明白你的问题,我在该路由层次结构下的 didInsertElement 中使用组件中的 sendAction,所以我猜它已加载。
-
其实我看到你的路线是索引路线,所以地图不能是父路线。为什么需要将模型设置在当前未激活的路径和模型上?
-
哦,我的错,我打错了,路线是 map.js 对不起,我更新问题
标签: ember.js