How to create Ext.data.Store from an unusual JSON store?

前端 未结 3 903
时光取名叫无心
时光取名叫无心 2021-01-15 00:38

I have this JSON store but it`s not coded correctly. What is the correct syntax for it?

Ext.define(\'MA.store.Language\', {
extend : \'Ext.data.Store\',
fiel         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 01:18

    Firstly, in your combobox configuration you must have: store : Ext.create('MA.store.Language'), instead of: store : 'Language',

    And secondly, your store definition must look like this:

    Ext.define('MA.store.Language', {
    extend : 'Ext.data.Store',
    fields : [ {
        name : 'id'
    }, {
        name : 'name'
    } ],
    data : [ {
        "aa" : "Afar",
        "ab" : "Abkhazian",
        "ace" : "Achinese",
        "ach" : "Acoli",
        "ada" : "Adangme",
        "ady" : "Adyghe",
        "ae" : "Avestan",
        "af" : "Afrikaans",
        "afa" : "Afro-Asiatic Language",
        "afh" : "Afrihili",
        "ain" : "Ainu",
        "ak" : "Akan"
    } ],
    
    read : function() {
     var me = this; 
     var oldData = me.getProxy().data[0];
     var data = [];
     for (var prop in oldData) {
        if (oldData.hasOwnProperty(prop)) {
            data.push({
                id: prop,
                name: oldData[prop]
            });
        }
     } 
     me.loadData(data);
    }
    
    });
    
    And it will work as you expect with your combobox.

    EDIT: instead of this:

    data.push({
        id: prop,
        name: oldData[prop]
      });
    
    I had this:
    data.push({
        id: prop,
        value: oldData[prop]
      });
    

提交回复
热议问题