使用控制器附加事件(sencha touch/extjs)

使用控制器附加事件(sencha touch/extjs),extjs,sencha-touch-2,Extjs,Sencha Touch 2,我在web编程方面的经验仅限于中级、自学成才的JS和jQuery以及少量PHP。ExtJS是一种完全不同的动物 我不明白为什么我的控制器没有达到我预期的效果,特别是因为我遵循了文档中使用的语法(由于它们无法描述示例中实际发生的情况,语法变得越来越无用……但我离题了) Main.js Ext.define("cs.view.Main", { extend: 'Ext.TabPanel', tabBarPosition: 'bottom',

我在web编程方面的经验仅限于中级、自学成才的JS和jQuery以及少量PHP。ExtJS是一种完全不同的动物

我不明白为什么我的控制器没有达到我预期的效果,特别是因为我遵循了文档中使用的语法(由于它们无法描述示例中实际发生的情况,语法变得越来越无用……但我离题了)

Main.js

    Ext.define("cs.view.Main", {
        extend: 'Ext.TabPanel',
        tabBarPosition: 'bottom',

        requires: [
            'cs.view.form',
            'cs.view.location',
            'Ext.TitleBar',
            'cs.controller.geolocate'
            ],

        config: {
            tabBar: {
                docked: 'bottom',
            },
            defaults: {
                flex: 1
            },
            items: [
                { xtype: 'form' },
                { xtype: 'location' }
                ]
            },
    });
Ext.define('cs.view.form', {
    extend: 'Ext.form.Panel',
    requires: 'cs.controller.geolocate',
    id: 'ClientFinderForm',

    config: {
        title: 'Home',
        iconCls: 'home',
        items: [
        {
            xtype: 'toolbar',
            docked: 'top',
            title: 'Client Finder'
        },
        {
            xtype: 'textfield',
            name: 'address',
            label: 'address'
        },
        {   
            xtype: 'textfield',
            name: 'dist',
            label: 'distance(mi)'
        },
        {
            xtype: 'button',
            ui: 'confirm',
            text: 'submit',
            id: 'submitButton',
        }
            ]
        },
});
Ext.define('cs.controller.geolocate', {
    extend: 'Ext.app.Controller',

    config: {
        control: {
            aButton: {
                tap: 'message'
            }
        },//control
        refs: {
            aButton: '#submitButton'
        },//refs
    },//config

    message: function(){
        Ext.Msg.alert("Success", "Finally!");
    }
});
form.js

    Ext.define("cs.view.Main", {
        extend: 'Ext.TabPanel',
        tabBarPosition: 'bottom',

        requires: [
            'cs.view.form',
            'cs.view.location',
            'Ext.TitleBar',
            'cs.controller.geolocate'
            ],

        config: {
            tabBar: {
                docked: 'bottom',
            },
            defaults: {
                flex: 1
            },
            items: [
                { xtype: 'form' },
                { xtype: 'location' }
                ]
            },
    });
Ext.define('cs.view.form', {
    extend: 'Ext.form.Panel',
    requires: 'cs.controller.geolocate',
    id: 'ClientFinderForm',

    config: {
        title: 'Home',
        iconCls: 'home',
        items: [
        {
            xtype: 'toolbar',
            docked: 'top',
            title: 'Client Finder'
        },
        {
            xtype: 'textfield',
            name: 'address',
            label: 'address'
        },
        {   
            xtype: 'textfield',
            name: 'dist',
            label: 'distance(mi)'
        },
        {
            xtype: 'button',
            ui: 'confirm',
            text: 'submit',
            id: 'submitButton',
        }
            ]
        },
});
Ext.define('cs.controller.geolocate', {
    extend: 'Ext.app.Controller',

    config: {
        control: {
            aButton: {
                tap: 'message'
            }
        },//control
        refs: {
            aButton: '#submitButton'
        },//refs
    },//config

    message: function(){
        Ext.Msg.alert("Success", "Finally!");
    }
});
geologite.js

    Ext.define("cs.view.Main", {
        extend: 'Ext.TabPanel',
        tabBarPosition: 'bottom',

        requires: [
            'cs.view.form',
            'cs.view.location',
            'Ext.TitleBar',
            'cs.controller.geolocate'
            ],

        config: {
            tabBar: {
                docked: 'bottom',
            },
            defaults: {
                flex: 1
            },
            items: [
                { xtype: 'form' },
                { xtype: 'location' }
                ]
            },
    });
Ext.define('cs.view.form', {
    extend: 'Ext.form.Panel',
    requires: 'cs.controller.geolocate',
    id: 'ClientFinderForm',

    config: {
        title: 'Home',
        iconCls: 'home',
        items: [
        {
            xtype: 'toolbar',
            docked: 'top',
            title: 'Client Finder'
        },
        {
            xtype: 'textfield',
            name: 'address',
            label: 'address'
        },
        {   
            xtype: 'textfield',
            name: 'dist',
            label: 'distance(mi)'
        },
        {
            xtype: 'button',
            ui: 'confirm',
            text: 'submit',
            id: 'submitButton',
        }
            ]
        },
});
Ext.define('cs.controller.geolocate', {
    extend: 'Ext.app.Controller',

    config: {
        control: {
            aButton: {
                tap: 'message'
            }
        },//control
        refs: {
            aButton: '#submitButton'
        },//refs
    },//config

    message: function(){
        Ext.Msg.alert("Success", "Finally!");
    }
});

我相信sencha touch 2希望您在应用程序中添加视图:[]。js

同样在cs.view.form中,您应该去掉xtype:“form”,它通过扩展Ext.form.panel已经知道它是一个表单


从提交按钮中去掉别名,您需要自己定义提交按钮才能使用别名

我相信sencha touch 2希望您在应用程序中添加视图:[]。js

同样在cs.view.form中,您应该去掉xtype:“form”,它通过扩展Ext.form.panel已经知道它是一个表单


从提交按钮中去掉别名,您需要自己定义提交按钮才能使用别名

发生了什么事?你说的“不按预期工作”是什么意思?说得更清楚些,我会帮你解决不工作的问题。我可以通过在form.js中添加一个
侦听器:
来直接添加事件。今天早些时候,有一个答案看起来很有用,但似乎已经消失了。。。关于将
init:
添加到geologite.js的内容发生了什么?你说的“不按预期工作”是什么意思?说得更清楚些,我会帮你解决不工作的问题。我可以通过在form.js中添加一个
侦听器:
来直接添加事件。今天早些时候,有一个答案看起来很有用,但似乎已经消失了。。。关于向geologite.js添加
init:
的内容