Да ExtJs все еще не имеет ридера, способного работать со списками строк. На стороне сервера (по крайней мере, в Java, C # и т. Д.) Это часто то, что вы получите при сортировке типов ENUM.
Мне пришлось написать свой собственный класс, который используется в стиле ExtJs 4.1 MVC:
/**
* This extends basic reader and is used for converting lists of enums (e.g. ['a', 'b', 'c']) into lists of objects:
* [ {name: 'a'}, {name:'b'}, {name:'c'}]. All models using this type of reader must have a single field called name. Or you can
* pass a config option call 'fieldName' that will be used.
*
* This assumes that the server returns a standard response in the form:
* { result: {...., "someEnum" : ['a', 'b', 'c']},
* total: 10,
* success: true,
* msg: 'some message'
* }
*/
Ext.define('MY.store.EnumReader', {
extend: 'Ext.data.reader.Json',
alias: 'reader.enum',
//we find the Enum value which should be a list of strings and use the 'name' property
getData: function(data) {
var me = this;
//console.dir(data);
var prop = Ext.isEmpty(this.fieldName) ? 'name' : this.fieldName;
console.log('Using the model property: \''+ prop +'\' to set each enum item in the array');
try {
var enumArray = me.getRoot(data);
//console.dir(enumArray);
if (!Ext.isArray(enumArray)){
console.error("expecting array of string (i.e. enum)");
throw new Exception('not an array of strings - enum');
}
var enumToObjArray = Array.map(enumArray, function(item){
var obj = {};
obj[prop] = item;
return obj;
}
);
//console.dir(enumToObjArray);
var nodes = me.root.split('.');
var target = data;
var temp = "data";
Array.forEach(nodes, function(item, index, allItems){
temp += "['" + item + "']";
});
temp += " = enumToObjArray";
//console.log('****************' + temp + '*****************');
//evil 'eval' method. What other choice do we have?
eval(temp);
//console.dir(data);
return data;
}
catch(ex){
console.error('coudln\'t parse json response: ' + response.responseText);
return this.callParent(response);
}
}
}, function() {
console.log(this.getName() + ' defined');
});
Затем, если вы хотите использовать этот тип ридера в своем магазине, вы добавляете:
requires: ['My.store.EnumReader'],
...
proxy: {
type: 'ajax',
url: ...
reader: {
type: 'enum',