【问题标题】:Sencha Touch - getting value from number fieldSencha Touch - 从数字字段中获取价值
【发布时间】:2013-04-14 06:48:29
【问题描述】:

我刚刚开始使用 Sencha Touch 2 框架,在跨设备复制表单行为方面遇到了一些困难。我有一个简单的搜索栏,用户在其中输入一个值(所有数字),然后选择它代表的内容(帐户、订单或电话号码)。当用户单击/点击搜索按钮时,它会获取输入字段的值和当前按下的数据类型按钮,并对 PHP 脚本进行 AJAX 查询。在 PC 上,它可以正常工作。在 iPad (6.1.3) 上,GET 请求不会到达服务器,并且 getValue 函数会报告 NULL,即使该字段已填充。我在这里错过了什么?

Ext.define('bazooka.view.Main', {
extend: 'Ext.tab.Panel',
requires: ['Ext.form.Panel', 'Ext.form.FieldSet', 'Ext.field.Text', 'Ext.field.Email', 'Ext.field.TextArea', 'Ext.field.Number', 'Ext.SegmentedButton'],

config: {
    fullscreen: true,
    tabBar: {
        ui: Ext.filterPlatform('blackberry') || Ext.filterPlatform('ie10') ? 'dark' : 'light',
        layout: {
            pack : 'center',
            align: 'center'
        },
        docked: 'bottom'
    },
    items: [
        {
            title: 'Home',
            iconCls: 'home',
            html: 'This will have news and updates for the department of the currently authenticated user.'
        },
        {
            title: 'Lookup',
            iconCls: 'search',
            items: [
                {
                    xtype: 'toolbar',
                    ui: Ext.filterPlatform('blackberry') || Ext.filterPlatform('ie10') ? 'dark' : 'light',
                    docked: 'top',
                    items: [
                        {
                            xtype: 'numberfield',
                            id: 'viki_searchbox',
                            autoComplete: false,
                            autoCorrect: false,
                            docked: 'left',
                            maxWidth: '40%'
                        },
                        {
                            xtype: 'segmentedbutton',
                            id: 'viki_seg_btn',
                            allowDepress: true,
                            items: [
                                {
                                    id: 'account',
                                    iconCls: 'user'
                                },
                                {
                                    id: 'workorder',
                                    iconCls: 'time'
                                },
                                {
                                    id: 'telephone',
                                    iconCls: 'more'
                                }
                            ]
                        },
                        {
                            xtype: 'button',
                            id: 'viki_searchbutton',
                            docked: 'right',
                            iconCls: 'search',
                            handler: function() {
                                var searchtype = Ext.getCmp('viki_seg_btn').getPressedButtons()[0]["id"];
                                var searchvalue = Ext.getCmp('viki_searchbox').getValue();
                                Ext.Viewport.setMasked({
                                    xtype: 'loadmask',
                                    message: 'Searching...'
                                });
                                Ext.Ajax.request({
                                    url: 'viki.php',
                                    method: 'GET',
                                    headers: {
                                        "Content-Type": "application/xml"
                                    },
                                    disableCaching: false,
                                    params: {
                                        type: searchtype,
                                        sv: searchvalue
                                    },
                                    timeout: 3000,
                                    failure: function(response) {
                                        console.log("oops");
                                    }
                                });
                                Ext.Viewport.setMasked(false);
                            }
                        }
                    ]
                }
            ]
        }
    ]
}
});

【问题讨论】:

    标签: javascript ajax html dom sencha-touch


    【解决方案1】:

    我不经常使用处理程序,我更喜欢点击事件。

    问题可能出在那个选择上。

    另外,如果我是你,我会使用 ItemId 而不是 Id 和 getComponent() 而不是 getCmp()。

    由于您的搜索按钮位于相同的视图表单中,因此您可以检索值

    searchbutton.getParent().getComponent('itemId').value;
    

    我提出这些建议,在使用全局对象(如 id 或 getCmp)时,我是否在 sencha 中遇到过很多奇怪的行为。使用 itemId 和 getComponent() 会更安全。

    【讨论】:

      【解决方案2】:

      看起来您的视图是一个数字字段。 如果用户输入包含非数字字符,数字字段将返回 null。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-28
        • 2011-11-24
        • 1970-01-01
        相关资源
        最近更新 更多