javascript - Sencha Touch - 从数字字段获取值

标签 javascript ajax html dom sencha-touch

我刚刚开始使用 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);
                            }
                        }
                    ]
                }
            ]
        }
    ]
}
});

最佳答案

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

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

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

由于您的搜索按钮位于同一 View 表单中,因此您将能够检索值

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

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

关于javascript - Sencha Touch - 从数字字段获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16128961/

相关文章:

javascript - Google Places Autocomplete - 点击模糊的第一个结果

javascript - 使用 SEQUELIZE 在 iLike 中使用 CAST 或 CONVERT 进行选择

jQuery 词云验证错误

html - 当我们使用 flex 调整窗口大小时,自动调整具有适当间隙和宽度的 div

javascript - 在 JavaScript 中混合命名和未命名参数?

javascript - IE : window. 打开超过2083个字符的url

php - 首次加载窗口时运行 onchange ajax

javascript - 帮助我正确进行 AJAX 调用

javascript - jquery ajax 调用没有按预期返回

html - 更改图像 onClick 和 onRelease?