如何获取所选Ext.form.field.PickerView项目的索引? 我正在尝试使用它:
$(function() {
yCategories = ['low', 'medium', 'high'];
$('#container').highcharts({
title: {
text: 'Chart with category axes'
},
xAxis: {
categories: ['Heroku', 'Ruby','Lisp','Javascript','Python','PHP']
},
yAxis: {
categories: yCategories
},
tooltip: {
formatter: function() {
return this.point.category + ': ' + yCategories[this.y];
}
},
series: [{
data: [0, 1, 2, 2, 1]
}]
});
});
但它不起作用..
答案 0 :(得分:0)
您可以使用indexOf()函数:
请检查小提琴: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))));
}
}
});
}
});
答案 1 :(得分:0)
我的解决方案:
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++;
});