Select 链式选择字段——Sencha Touch 2.0
我正在使用Sencha Touch 2.0 KitchenSink示例来尝试学习一些基础知识。不过,我被链式选择字段卡住了 我要离开这里,但与不同的设置,我被甩了。下面的代码在kitchensink中的Forms.js文件中运行得非常好,但我缺少其中实际的chainedselect部分 编辑:我要问的是如何制作链接的selectfields。我在示例代码中有数据存储和selectfields,但没有从第一个到第二个链接的selectfieldSelect 链式选择字段——Sencha Touch 2.0,select,sencha-touch,sencha-touch-2,Select,Sencha Touch,Sencha Touch 2,我正在使用Sencha Touch 2.0 KitchenSink示例来尝试学习一些基础知识。不过,我被链式选择字段卡住了 我要离开这里,但与不同的设置,我被甩了。下面的代码在kitchensink中的Forms.js文件中运行得非常好,但我缺少其中实际的chainedselect部分 编辑:我要问的是如何制作链接的selectfields。我在示例代码中有数据存储和selectfields,但没有从第一个到第二个链接的selectfield Ext.regModel('First', { id
Ext.regModel('First', {
idProperty: 'FirstID',
fields: [{
name: 'FirstID',
type: 'int'
}, {
name: 'FirstName',
type: 'string'
}]
});
Ext.regModel('Second', {
idProperty: 'SecondID',
fields: [{
name: 'SecondID',
type: 'int'
},{
name: 'FirstID',
type: 'int'
}, {
name: 'SecondName',
type: 'string'
}]
});
var firstStore = new Ext.data.Store({
model: 'First',
data: [{
FirstID: 1,
FirstName: 'Kenworth'
}, {
FirstID: 2,
FirstName: 'Peterbilt'
}],
autoLoad: true
});
var secondStore = new Ext.data.Store({
model: 'First',
data: [{
SecondID: 1,
FirstID: 1,
SecondName: 'T800'
}, {
SecondID: 2,
FirstID: 1,
SecondName: 'T700'
}, {
SecondID: 3,
FirstID: 1,
SecondName: 'T660'
}, {
SecondID: 4,
FirstID: 1,
SecondName: 'T470'
}],
autoLoad: true
});
Ext.define('Kitchensink.view.Forms', {
extend: 'Ext.tab.Panel',
requires: [
'Ext.form.Panel',
'Ext.form.FieldSet',
'Ext.field.Number',
'Ext.field.Spinner',
'Ext.field.DatePicker',
'Ext.field.Select',
'Ext.field.Hidden'
],
config: {
activeItem: 0,
tabBar: {
// docked: 'bottom',
ui: 'dark',
layout: {
pack: 'center'
}
},
items: [
{
title: 'Basic',
xtype: 'formpanel',
id: 'basicform',
iconCls: 'refresh',
items: [
{
xtype: 'fieldset',
title: 'Enter Data',
instructions: 'Please enter the information above.',
defaults: {
labelWidth: '35%'
},
items: [
{
xtype: 'selectfield',
name: 'firstfield',
label: 'First',
store: firstStore,
displayField: 'FirstName',
valueField: 'FirstID'
}, {
xtype: 'selectfield',
name: 'secondfield',
label: 'Second',
store: secondStore,
displayField: 'SecondName',
valueField: 'SecondID'
}
]
}
]
}
]
},
onFirstChange: function(selectField, value){
var secondSelectField = this.items.get(1);
secondSelectField.store.clearFilter(); // remove the previous filter
// Apply the selected Country's ID as the new Filter
secondSelectField.store.filter('FirstID', value);
// Select the first City in the List if there is one, otherwise set the value to an empty string
var firstValue = secondSelectField.store.getAt(0);
if(firstValue){
secondSelectField.setValue(firstValue.data.SecondID);
} else {
secondSelectField.setValue('');
}
}
});
你不是在第二家店用错型号了吗?模型应该是“第二个”,而不是“第一个”。一旦这样做了,在firstValue.data.SecondID处获取值应该不会有问题。从我可以看出,您使用了错误的模型,在您使用的“First”模型中,没有名为“firstValue.data.SecondID”的值,这就是为什么返回空字符串的原因。