如何获取所选 Ext.form.field.PickerView 项的索引?
How to get index of selected Ext.form.field.PickerView item?
如何获取所选 Ext.form.field.PickerView 项的索引?
我正在尝试使用它:
Ext.define('Bind.CL.FormD.view.MyCombo', {
extend: 'Ext.form.field.Picker',
alias: 'widget.mycombo',
...something code...
this.on('expand', function () {
var combo = Ext.ComponentQuery.query('mycombo')[0];
var value = combo.getValue(); //or getRawValue();
}, this);
但是不行..
您可以使用 indexOf() 函数:
请检查 Fiddle : https://fiddle.sencha.com/#fiddle/1i0o
Ext.application({
name: 'Fiddle',
launch: function() {
simpsonsStore = Ext.create('Ext.data.Store', {
storeId : 'simpsonsStore',
fields : ['id','name', 'email'],
data : [
{name : 'Lisa',email : 'lisa@simpsons.com',id:1},
{name : 'Bart', email : 'bart@simpsons.com',id:2},
{name : 'Homer', email : 'homer@simpsons.com',id:3},
{name : 'Marge',email : 'marge@simpsons.com',id:4}
]
});
Ext.create('Ext.form.field.ComboBox', {
emptyText: "Hello",
growMax: 10,
valueField: 'id',
store:simpsonsStore,
displayField: 'name',
editable: false,
queryMode: 'local',
renderTo: Ext.getBody(),
listeners:{
change:function(combo){
console.log(combo.store.indexOf((combo.store.getById(combo.value))));
}
}
});
}
});
我的解决方案:
this.on('expand', function () {
var combo = Ext.ComponentQuery.query('mycombo')[0],
value = combo.getValue(),
root = value.store.tree.getRootNode(),
record = root.childNodes,
currentValue = combo.getValue().data.Code,
index = 0;
Ext.each(record, function(element) {
var data = element.getData();
if (data.Code === currentValue) {
return false;
}
index++;
});
如何获取所选 Ext.form.field.PickerView 项的索引? 我正在尝试使用它:
Ext.define('Bind.CL.FormD.view.MyCombo', {
extend: 'Ext.form.field.Picker',
alias: 'widget.mycombo',
...something code...
this.on('expand', function () {
var combo = Ext.ComponentQuery.query('mycombo')[0];
var value = combo.getValue(); //or getRawValue();
}, this);
但是不行..
您可以使用 indexOf() 函数:
请检查 Fiddle : https://fiddle.sencha.com/#fiddle/1i0o
Ext.application({
name: 'Fiddle',
launch: function() {
simpsonsStore = Ext.create('Ext.data.Store', {
storeId : 'simpsonsStore',
fields : ['id','name', 'email'],
data : [
{name : 'Lisa',email : 'lisa@simpsons.com',id:1},
{name : 'Bart', email : 'bart@simpsons.com',id:2},
{name : 'Homer', email : 'homer@simpsons.com',id:3},
{name : 'Marge',email : 'marge@simpsons.com',id:4}
]
});
Ext.create('Ext.form.field.ComboBox', {
emptyText: "Hello",
growMax: 10,
valueField: 'id',
store:simpsonsStore,
displayField: 'name',
editable: false,
queryMode: 'local',
renderTo: Ext.getBody(),
listeners:{
change:function(combo){
console.log(combo.store.indexOf((combo.store.getById(combo.value))));
}
}
});
}
});
我的解决方案:
this.on('expand', function () {
var combo = Ext.ComponentQuery.query('mycombo')[0],
value = combo.getValue(),
root = value.store.tree.getRootNode(),
record = root.childNodes,
currentValue = combo.getValue().data.Code,
index = 0;
Ext.each(record, function(element) {
var data = element.getData();
if (data.Code === currentValue) {
return false;
}
index++;
});