Javascript 助手函数中的成员绑定返回未定义的
尝试创建与用户id匹配的简单帮助器。其中一个值是Javascript 助手函数中的成员绑定返回未定义的,javascript,ember.js,Javascript,Ember.js,尝试创建与用户id匹配的简单帮助器。其中一个值是Ember.binding,该值返回未定义的值 controller.js App.WorkspacesTasksController = Ember.ArrayController.extend({ needs: 'application', currentUserBinding: 'controllers.application.currentUser', ... }); Ember.Handlebars.registerHe
Ember.binding
,该值返回未定义的值
controller.js
App.WorkspacesTasksController = Ember.ArrayController.extend({
needs: 'application',
currentUserBinding: 'controllers.application.currentUser',
...
});
Ember.Handlebars.registerHelper('isCurrentUser', function(currentUserId, taskUserId, options){
currentUserId = Ember.Handlebars.get(this, currentUserId, options);
taskUserId = Ember.Handlebars.get(this, taskUserId, options);
if (currentUserId === taskUserId) {
return true;
} else {
return false;
}
});
helper.js
App.WorkspacesTasksController = Ember.ArrayController.extend({
needs: 'application',
currentUserBinding: 'controllers.application.currentUser',
...
});
Ember.Handlebars.registerHelper('isCurrentUser', function(currentUserId, taskUserId, options){
currentUserId = Ember.Handlebars.get(this, currentUserId, options);
taskUserId = Ember.Handlebars.get(this, taskUserId, options);
if (currentUserId === taskUserId) {
return true;
} else {
return false;
}
});
我在模板中这样称呼它:
{{#isCurrentUser currentUser.id task.userObject.id}}
Matching users
{{/isCurrentUser}}
当我这样做时:console.log(currentUserId)代码>在我的助手中,我得到未定义的
我做错了什么?如果(true)返回true,否则返回false
,哦,天哪。您可以只编写返回currentUserId===taskUserId
。好的一点,但没有回答这个问题。