mardi 3 février 2015

How can I refresh an input control in Emberjs after setting a value in a computed property?

Id like to be able to refresh the input control with the repaired value, so, after setting a 0 or negative value, I'd like the control to show number 1.



App.PageNavigationComponent = Ember.Component.extend({
current: 0,
currentForUser: function(k, v){
if(arguments.length > 1){
this.set('current', this._repairValue(v - 1));
}
return this.get('current') + 1;
}.property('current'),

_repairValue: function(v) {
return v > 0 ? v : 0;
}
});

App.ApplicationController = Ember.Controller.extend({
current: 0
});


Templates



<script type="text/x-handlebars">
{{page-navigation current=current}}
Current value: {{current}}
</script>

<script type="text/x-handlebars" data-template-name="components/page-navigation">
{{input value=currentForUser}}
</script>


With the current code, when I set for example the value -1 in the control, it does not change, however the text Current value: 1 changes accordingly.


Is there any way to achieve this?


http://ift.tt/1HRSLmh


Aucun commentaire:

Enregistrer un commentaire