extjs
Modello di evento
Ricerca…
introduzione
ExtJS sostiene l'uso di sparare e ascoltare eventi tra classi. Licenziando gli eventi e ascoltando gli eventi licenziati, le classi non richiedono conoscenze "sporche" sulla struttura delle classi degli altri e prevengono il codice di accoppiamento. Inoltre, gli eventi facilitano l'ascolto di più istanze dello stesso componente consentendo un listener generico per tutti gli oggetti con lo stesso selettore. Infine, anche altre classi potrebbero essere in grado di utilizzare eventi già esistenti.
Controller Ascoltare i componenti
Ext.define('App.Duck', {
extend: 'Ext.Component',
alias: 'widget.duck',
initComponent: function () {
this.callParent(arguments);
this._quack();
},
_quack: function () {
console.log('The duck says "Quack!"');
this.fireEvent('quack');
},
feed: function () {
console.log('The duck looks content.');
},
poke: function () {
this._quack();
}
});
var feedController = Ext.create('Ext.app.Controller', {
listen: {
components: {
duck: {
quack: 'feedDuck'
}
}
},
feedDuck: function (duck) {
duck.feed();
}
});
var countController = Ext.create('Ext.app.Controller', {
listen: {
components: {
duck: {
quack: 'addCount'
}
}
},
quackCount: 0,
addCount: function (duck) {
this.quackCount++;
console.log('There have been this many quacks: ' + this.quackCount);
}
});
var firstDuck = Ext.create('App.Duck');
// The duck says "Quack!"
// The duck looks content.
// There have been this many quacks: 1
var secondDuck = Ext.create('App.Duck');
// The duck says "Quack!"
// The duck looks content.
// There have been this many quacks: 2
firstDuck.poke();
// The duck says "Quack!"
// The duck looks content.
// There have been this many quacks: 3
Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow