[英]EmberJS - Observing changes in an {{input}}-Helper in a controller
i have a {{input}}-helper in my template and i want to fire a method in the controller for every change in the {{input}}-helper. 我的模板中有一个{{input}}-helper,我想为{{input}}-helper中的每个更改在控制器中激发一个方法。
application.hbs application.hbs
<div class="page" id="main">
{{input type="text" id="note-title" value=noteTitle action="createNote"}}
</div>
application_controller.js application_controller.js
YeoApp.ApplicationController = Ember.ArrayController.extend({
actions: {
searchTextChanged: function() {
// this method should be called whenever
// the input value changes, but somehow it doesn't work
}.observes("noteTitle"),
anotherMethod: function() {
this.set("noteTitle", "Test!");
//even this doesn't fire the observer when called
}
}
});
Any suggestions? 有什么建议么? Thanks in advance.
提前致谢。 Don't be afraid to ask questions.
不要害怕问问题。
I think that using observes inside of the actions
hash don't work. 我认为在
actions
哈希内部使用观察不起作用。 You need to extract the searchTextChanged
outside of that object: 您需要将
searchTextChanged
提取到该对象之外:
YeoApp.ApplicationController = Ember.ArrayController.extend({
searchTextChanged: function() {
// this method should be called whenever
// the input value changes, but somehow it doesn't work
}.observes("noteTitle"),
actions: {
anotherMethod: function() {
this.set("noteTitle", "Test!");
//even this doesn't fire the observer when called
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.