Sencha Touch 2 MVC 列表事件接线

发布于 2024-12-29 13:45:28 字数 1987 浏览 5 评论 0原文

我正在尝试遵循此 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]);
},
});

这里的事件接线有什么问题?

I am trying to follow this Sencha Touch 2 MVC example: https://github.com/FrancisShanahan/SenchaTouch2MVCHelloworld.

The onStationSelect event does not work:

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]);
},
});

What is wrong with the event wiring here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别把无礼当个性 2025-01-05 13:45:28

我想通了。缺失的部分是:

this.control({
    'list' : {
        itemtap : this.onStationSelect
    }
});

I figured it out. The missing part was:

this.control({
    'list' : {
        itemtap : this.onStationSelect
    }
});
梦回旧景 2025-01-05 13:45:28

这篇文章和教程的组合“如何创建 Sencha Touch 2 应用程序,第 1 部分” 帮助我更好地理解控制器中的 controlrefs。我想我会分享。

A combination of this post and the tutorial 'How to Create a Sencha Touch 2 App, Part 1' helped me understand control and refs in a controller better. Thought I would share.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文