【发布时间】:2014-07-29 11:04:09
【问题描述】:
我正在尝试在路由的渲染模板中设置模型。模型正在通过模板调用正确捕获:
{{#each itemController="user"}}
<div {{bind-attr class="isExpanded:expanded"}}>
<div><button {{action "sayHello" this}}>{{first_name}} {{last_name}}</button></div>
和我的路线:
Newkonf.UsersRoute = Ember.Route.extend({
isExpanded: false,
actions: {
sayHello: function(myModel){
alert('first name: ' + myModel.first_name); // <- this works
// this.render('edit-user', {model: myModel}); <- doesn't work but not sure since this leads me to susupec
// it might https://github.com/emberjs/ember.js/issues/1820
// this.set('model', myModel}); <- doesn't work
this.render('edit-user');
}
}
}
车把是:
going to edit user here first name: {{first_name}}
编辑 1
我可以在 UsersRoute 中更新消息,它会相应地更新。我有点因为我指定了 UserController 会导致 UserRoute 优先,但我想不会。
这是我的路由器:
Newkonf.Router.map(function() {
// this.resource('posts');
this.route('about', { path: '/about'});
this.resource('users', { path: '/users'});
});
编辑 2
我必须像这样处理我的 modal.js.hbs:
within modal for you:
{{model.first_name}}
因为这不起作用:
within modal for you:
{{first_name}}
不知道为什么。
这是我的路线:
Newkonf.ApplicationRoute = Ember.Route.extend({
actions:{
somePlace: function(item){
alert('here i am in somePlace: ' + item.last_name); // <- this works
var modalController = this.controllerFor('modal');
modalController.set('model', item);
var myjt=modalController.get('model');
console.log('my value:' + myjt.first_name); // <- this works
this.render('modal', {
into: 'application',
outlet: 'modal3',
controller: modalController
});
}
}
});
而且没有控制器。
【问题讨论】:
-
你会展示你的路由器吗?当您单击操作时,您是否在用户路线中?
-
您的主要目标是用不同的模板替换用户模板吗?
-
我最终希望在一个新的“模态”插座中呈现一个模板,并且不替换当前的插座模板,而只是希望现在能够传递模型。
标签: ember.js