在我的Sencha touch应用程序中,我通过从json对象动态创建表单项来填充容器。
对于文本字段,我使用的代码如下:
Ext.getCmp('mytestpanel').add({
xtype: response.screens[index].screenItems[i].xtype,
id:response.screens[index].screenItems[i].name,
label: response.screens[index].screenItems[i].title,
name: response.screens[index].screenItems[i].name
}
});
json使用了:
{
"screens": [
{
"screenname": "Screen 1",
"screenItems": [
{"xtype": "textfield", "title": "Temperature"," name": "textfield1", "value":"service211"},
{"xtype": "button", "title": "Update", "name": "button1"}
]
},
{
"screenname": "Screen 2",
"screenItems": [
{"xtype": "emailfield", "title": "screen2"," name": "textfield2"},
{"xtype": "checkboxfield", "title": "label3", "name": "textfield13"},
{"xtype": "selectfield", "title": "Submit", "name": "button11"}
]
}
]
}
我需要使用json
中的web服务来更新此文本字段的值{“xtype”:“textfield”,“title”:“Temperature”,“name”:“textfield1”,“value”:“someservice211”}
由于价值是实时的,我该怎么做呢?
答案 0 :(得分:2)
使用商店阅读json怎么样?你可以将setInterval设置为store.load(),然后在加载回调上添加/编辑动态项:
proxy: {
type: 'ajax',
url: 'http://URL',
reader: {
type: 'json',
rootProperty: 'screens'
}
},
autoLoad: true,
listeners: {
initialize: function() {
var interval = setInterval(function() {
Ext.StoreMgr.lookup('myStore').load();
}, 2000);
},
load: function(st) {
var testPanel = Ext.getCmp('mytestpanel');
Ext.each(st, function(record) {
var obj = Ext.getCmp(record.get('id'));
if (obj) {
if (record.get('value')) obj.setValue(record.get('value'));
} else {
testPanel.add({
xtype: record.get('xtype'),
id: record.get('id'),
label: record.get('label'),
name: record.get('name'),
value: record.get('value')
});
}
}
}
}
希望它有所帮助 -