[英]Sencha Touch - getting value from number field
I've just gotten started using the Sencha Touch 2 framework, and am having some difficulty in replicating form behaviour across devices. 我刚刚开始使用Sencha Touch 2框架,并且在跨设备复制表单行为时遇到了一些困难。 I have a simple search bar, where a user enters a value (all numbers), and chooses what it represents (an account, order, or phone number). 我有一个简单的搜索栏,用户可以在其中输入一个值(所有数字),然后选择它代表的内容(帐户,订单或电话号码)。 When a user clicks/taps on the search button, it grabs the value of the input field and the currently pressed data-type button and makes an AJAX query to a PHP script. 当用户单击/轻按搜索按钮时,它将获取输入字段和当前按下的数据类型按钮的值,并对PHP脚本进行AJAX查询。 On a PC, it works without issue. 在PC上,它可以正常工作。 On an iPad (6.1.3), the GET request doesn't hit the server, and the getValue function reports a NULL, even when the field is filled. 在iPad(6.1.3)上,GET请求不会到达服务器,并且即使填充了字段,getValue函数也会报告NULL。 What am I missing here? 我在这里想念什么?
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);
}
}
]
}
]
}
]
}
});
I don't use handler often, I prefer Tap Events. 我不经常使用处理程序,我更喜欢Tap Events。
The problem might be that choice. 问题可能在于选择。
Plus, if I were you I would be using ItemId and not Id and getComponent() and not getCmp(). 另外,如果您是我,我将使用ItemId而不是Id和getComponent()而不是getCmp()。
Since your search button is in the same view form it you would be able to retrieve values 由于您的搜索按钮具有相同的视图形式,因此您可以检索值
searchbutton.getParent().getComponent('itemId').value;
I make these recommandations, has I experienced lots of strange behavior in sencha when using global object (like id or getCmp). 我提出了这些建议,使用全局对象(例如id或getCmp)时,在sencha中遇到了很多奇怪的行为。 it would be safer with itemId and getComponent(). 使用itemId和getComponent()会更安全。
Looks like you're view is a numberfield. 看来您正在查看的是一个数字字段。 Number field will return null if there's user input that has non-numeric characters. 如果用户输入包含非数字字符,则“数字”字段将返回null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.