admin管理员组文章数量:1316834
This is a reduced version of my code but it still illustrates the issue I'm having. I'm trying to bind the puted property value with textValue.
Please note, that I know I can just do the basic as shown in this fiddle but this does not meet my needs.
In the large version of this code, not illustrated here, I perform modifications to value
before setting and modification to text
after getting. That's the gist of why I can't just use the default binding illustrated in the above fiddle.
JS
var App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend({
text: "Default",
textValue: function(key, value) {
if(arguments.length === 1) {
return this.get('text');
} else {
this.set('text', value);
}
}.property('text')
});
HTML
<script type="text/x-handlebars" data-template-name="application">
{{input value=textValue}}
<br>
TextValue: {{textValue}}
</script>
Fiddle
Thanks in advance!
This is a reduced version of my code but it still illustrates the issue I'm having. I'm trying to bind the puted property value with textValue.
Please note, that I know I can just do the basic as shown in this fiddle but this does not meet my needs.
In the large version of this code, not illustrated here, I perform modifications to value
before setting and modification to text
after getting. That's the gist of why I can't just use the default binding illustrated in the above fiddle.
JS
var App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend({
text: "Default",
textValue: function(key, value) {
if(arguments.length === 1) {
return this.get('text');
} else {
this.set('text', value);
}
}.property('text')
});
HTML
<script type="text/x-handlebars" data-template-name="application">
{{input value=textValue}}
<br>
TextValue: {{textValue}}
</script>
Fiddle
Thanks in advance!
Share Improve this question asked Mar 16, 2014 at 8:48 EasyCoEasyCo 2,03621 silver badges39 bronze badges2 Answers
Reset to default 5As of Ember.js 1.12, checking of arguments length is deprecated, since the discrete setter/getters for puted properties has been adopted.
textValue: Ember.puted('text', {
get() {
return this.get('text');
},
set(value) {
this.set('text', value);
}
})
It is required to return a value for your puted property
http://jsfiddle/EW7xD/2/
js
App.ApplicationController = Ember.Controller.extend({
text: "Default",
textValue: function(key, value) {
if(arguments.length === 1) {
return this.get('text');
} else {
this.set('text', value);
return this.get('text');
}
}.property('text')
});
or maybe simplify it
App.ApplicationController = Ember.Controller.extend({
text: "Default",
textValue: function(key, value) {
if(arguments.length > 1) {
this.set('text', value);
}
return this.get('text');
}.property('text')
});
本文标签: javascriptEmberJS Computed property with getset rendered in templateStack Overflow
版权声明:本文标题:javascript - EmberJS: Computed property with getset rendered in template - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742001463a2411097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论