我正在尝试按照Sencha Touch 2 MVC示例:https://github.com/FrancisShanahan/SenchaTouch2MVCHelloworld。
onStationSelect事件不起作用:
Ext.define('HelloWorld.controller.Home', {
extend: 'Ext.app.Controller',
views: ['Home', 'SimpleList'],
stores: ['Stations'],
// These "refs" will generate "getters" for each of the view component instances
// e.g. getBottomField and getStationList
refs: [{
selector: 'carousel > panel > #bottomInput',
ref: 'bottomField'
},
{
selector: 'carousel > list',
ref: 'stationList'
}
],
init: function() {
console.log('Init home controller');
// Start listening for events on views
this.control({
// example of listening to *all* button taps
'button': { 'tap': function () {
console.log('Every button says Hello world');
}
},
// Example of listening by an explicit id
'#firstButton': { 'tap': function () {
console.log('Only the button with id=firstButton says Hello');
alert(this.getBottomField().getValue());
}
}
});
},
onLaunch: function() {
console.log('onLaunch home controller');
// The "getter" here was generated by specifying the
// stores array (above)
var stationsStore = this.getStationsStore();
stationsStore.load({
callback: this.onStationsLoad,
scope: this
});
},
onStationsLoad: function() {
console.log('onStationsLoad home controller');
// get a reference to the view component
var stationsList = this.getStationList();
// do something
},
onStationSelect: function(selModel, selection) {
// Fire an application wide event
this.application.fireEvent('stationstart', selection[0]);
},
});
这里的事件接线有什么问题?
答案 0 :(得分:1)
我明白了。缺少的部分是:
this.control({
'list' : {
itemtap : this.onStationSelect
}
});
答案 1 :(得分:0)
这篇文章与the tutorial 'How to Create a Sencha Touch 2 App, Part 1'的组合帮助我更好地理解了控制器中的control
和refs
。以为我会分享。