JSON记录中的Sencha填充选项卡
Sencha fill tab from JSON record
我的JSON文件:
{
"options":{
"someString": "SomeText",
"someNumber": 42,
"someCombo": 2,
"someBool" : true
}
}
我为那个JSON文件制作了一个JSON存储,它加载正确。
现在,我的选项选项卡:
items: [
{
xtype: 'panel',
layout: {
align: 'stretch',
type: 'vbox'
},
title: 'Options Tab',
tabConfig: {
xtype: 'tab',
flex: 1
},
items: [
{
xtype: 'textfield',
id: 'someString',
fieldLabel: 'Some String:',
},
{
xtype: 'numberfield',
id: 'someNumber',
fieldLabel: 'Some Number',
},
{
xtype: 'combobox',
id: 'someCombo',
fieldLabel: 'Some Combo',
editable: false,
store: [['0','Option Zero'],['1','Option One'],['2','Option Two']]
},
{
xtype: 'checkboxfield',
id: 'someBool',
fieldLabel: 'Some Boolean',
boxLabel: 'Yes'
}
]
}
]
经过多次尝试,我还没有找到用JSON数据填充表单元素的方法:
onJsonstoreLoad: function(store, records, successful, eOpts) {
// this.child("#sepString").update(store.getAt(0).fields.getByKey("sepString"));
// Ext.fly("someString").update(store.getAt(0).fields.getByKey("someString"));
// Ext.fly("someString").setValue(store.getAt(0).fields.getByKey("someString"));
Ext.fly("someString").value=store.getAt(0).fields.getByKey("someString");
...
Ext.fly("someBool").checked=store.getAt(0).fields.getByKey("someBool");
}
那么,如何将数据导入表单元素呢?
使用FormPanel
及其loadRecord
方法。你也应该看看Ext.form.Basic#setValues
。
var formPanel = Ext.widget({
xtype: 'form', // Use form xtype instead of panel
renderTo: Ext.getBody(),
layout: {
align: 'stretch',
type: 'vbox'
},
title: 'Options Tab',
tabConfig: {
xtype: 'tab',
flex: 1
},
items: [{
xtype: 'textfield',
// We need names, not ids
name: 'someString',
fieldLabel: 'Some String:',
},{
xtype: 'numberfield',
name: 'someNumber',
fieldLabel: 'Some Number',
},{
xtype: 'combobox',
name: 'someCombo',
fieldLabel: 'Some Combo',
editable: false,
store: [['0','Option Zero'],['1','Option One'],['2','Option Two']]
},{
xtype: 'checkboxfield',
name: 'someBool',
fieldLabel: 'Some Boolean',
boxLabel: 'Yes'
}]
});
// Create a mock record
var MyRecord = Ext.define(null, {
extend: 'Ext.data.Model'
,fields: ['someString', 'someNumber', 'someCombo', 'someBool']
});
var record = new MyRecord({
"someString": "SomeText",
"someNumber": 42,
"someCombo": 2,
"someBool" : true
});
// You would use the record loaded in your store instead:
// var record = store.getAt(0);
// In recent version of Ext4, you can call formPanel.loadRecord directly
formPanel.getForm().loadRecord(record);
相关文章:
- 如何将CSS(特别是填充/边距)应用于select下拉菜单的选项或optgroup
- 使用jquery在选择框中的选项中填充数据
- 解析和填充 jQuery 插件的选项数组
- 动态下拉列表选项在添加多列后未填充
- 使用 ajax 填充选择时没有选定的默认选项的问题
- 使用数组中的选项填充选择菜单
- 如何填充下拉列表,从javascript中的另一个下拉列表中排除任何一个选项
- 创建唯一选项,然后使用 JavaScript 填充多个选择
- 通过遍历JSON文件来填充数据列表选项
- JSON记录中的Sencha填充选项卡
- 如何在选择下拉列表中填充选项值
- 动态创建选择元素并从 SharePoint 列表填充选项
- 动态填充选项在搜索框(选择)bootstrap jquery
- 如何在承诺后用angular ui-select填充选项
- 在angular auth0中包括预填充选项
- 自动填充选项在没有明显原因的情况下消失或重新出现
- html select-用JavaScript填充选项text/值
- asp:DropDownList通过javascript填充选项,不使用clientSideId
- 使用javascript选中复选框时,填充选项列表
- 选择在动态填充选项时更新占位符文本