Ember-如何创建和绑定Checkbox控制器? [英] Ember - how to create and bind a Checkbox controller?
本文介绍了Ember-如何创建和绑定Checkbox控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此问题与此处给出的答案相关。
This question is linked to the answer given here.
在视图中具有复选框
App.RoleCheckbox = Em.Checkbox.extend({
userRolesBinding: 'parentView.user.roles', // Points to the roles of the user
checked: function () {
var userRoles = this.get('userRoles');
return userRoles.contains(this.get('content'));
}.property('content', 'userRoles.@each'),
click: function (evt) {
//do something
var controller = this.get("controller");
controller.clicked(evt);
}
});
我希望click函数从RoleCheckboxController调用被单击的函数:
I would like that the click function calls the clicked function from the RoleCheckboxController:
App.RoleCheckboxController = Em.Controller.extend({
clicked: function(evt){
//Really do the thing
}
});
但这不起作用。我该如何解决?
But this does not work. How could I fix this ?
JSFiddle: http:// jsfiddle.net/3fMpD/
JSFiddle: http://jsfiddle.net/3fMpD/
推荐答案
您可以使用正确的命名约定。
例如,这会将控制器与视图关联:
For example, this would associate the controller to the view:
// Instead of App.RoleCheckBoxController
App.ApplicationController = Ember.Controller.extend( /* ... */ );
App.ApplicationView = Ember.View.extend( /* .. */ );
JSFiddle: http://jsfiddle.net/YL5rQ/
JSFiddle: http://jsfiddle.net/YL5rQ/
这篇关于Ember-如何创建和绑定Checkbox控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文