我有一个类似的表单,当我想在 newItem 控制器中获取提交的值时,我会得到“未定义”的值。怎么了?
<form role="form" {{ action 'add' target="newItem" on="submit"}}>
<h2>New category</h2>
<div class="form-group">
<label>Category title</label>
{{input value=title class="form-control" type="text" placeholder="Title"}}
</div>
<div class="form-group">
<label>Category description</label>
{{textarea value=description class="form-control" placeholder="Description"}}
</div>
<div class="form-group">
{{input type="submit" class="btn" }}
</div>
</form>
App.NewItemController = Ember.ObjectController.extend({
add: function(){
console.log(this.get('title')); // undefined
}
});
更新:
此表格在 ApplicationRoute 上:
App.ApplicationRoute = Ember.Route.extend({
setupController: function(controller, model) {
var newItem = this.controllerFor('NewItem');
controller.set('newItem', newItem);
}
});