Initier le flou/la mise au point sur certains changements de propriété
-
14-11-2019 - |
Question
j'ai un Ember.TextField
à mon avis.J'aimerais que le champ se concentre lorsqu'une certaine propriété de l'application change.J'ai appris à lier les rappels à l'événement focus, mais existe-t-il un moyen d'initier le focus d'un champ basé sur une liaison ?
La solution
Un simple violon qui, je pense, fait ce que vous demandez.
http://jsfiddle.net/algesten/MGfAd/1/
Code pour être complet :
window.App = Ember.Application.create();
App.model = Ember.Object.create({
someProp: 123,
});
App.MyTextField = Ember.TextField.extend({
value: 'foo',
autoFocus: function () {
if (App.model.someProp === "42") {
this.$().focus();
}
}.observes('App.model.someProp')
});
HTML :
<script type="text/x-handlebars">
{{view App.MyTextField}}
</script>
<br/>Try changing this field to '42' and see that the focus moves.
<script type="text/x-handlebars">
{{view Ember.TextField valueBinding="App.model.someProp"}}
</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow