ExtJS:连接一个存储到一个组合框

ExtJS: Connecting a store to a combo box?

本文关键字:一个 组合 ExtJS 连接 存储      更新时间:2023-09-26

在下面的代码中,我手动向存储(称为dataStore)添加记录。但是当我尝试将存储加载到组合框(标记为cmb)时,我得到以下错误:

http://localhost: 1841/CurrencyConvert.model.CurrencyCode ? _dc = 147 hj_126&查询=,= 1页,= 0开始,限制= 25404(未找到)

看起来好像商店正在尝试调用代理来加载数据(即使它已经拥有所有数据,由我手动加载)。以下是存储:

Ext.define('CurrencyConvert.store.CurrencyCode', {
    extend : 'Ext.data.Store',
    model : 'CurrencyConvert.model.CurrencyCode',
    storeId : 'currencyCode',
    addRate : function(currencyCode, currencyRate) {
        this.add({
            code : currencyCode,
            rate : currencyRate
        });
    }
});

和正在使用存储的Ajax请求:

Ext.Ajax.request({
                    url : 'data.json',
                    method : 'GET',
                    dataType: 'currency.json',
                    item : cmb,
                    success: function(response)
                    {
                        console.log('Success');
                        var result = Ext.JSON.decode(response.responseText);
                        var currencyCodes = Object.keys(result.quotes);
                        this.dataStore = Ext.create('CurrencyConvert.store.CurrencyCode', {});
                        for( var x = 0; x < currencyCodes.length; x++)
                        {
                            this.dataStore.addRate(currencyCodes[x], result.quotes[currencyCodes[x]]);
                            console.log(this.dataStore.getAt(x).get('code') + " : " + this.dataStore.getAt(x).get('rate'));
                        }
                        cmb.emptyText = "-Chose Currency-";
                        cmb.store = this.dataStore;
                        console.log("Stuff: " + this.dataStore.getAt(2).get('code') + " : " + this.dataStore.getAt(2).get('rate'));         
                        cmb.displayField = 'code';
                        cmb.valueField = 'code';        

                    },
                    failure: function(response) {
                        console.log('Failed!');
                        console.log(response);
                    },
                });

以下是我正在抓取的样本数据:

{
  "success":true,
  "terms":"https:'/'/currencylayer.com'/terms",
  "privacy":"https:'/'/currencylayer.com'/privacy",
  "timestamp":1475354167,
  "source":"USD",
  "quotes":{
    "USDAED":3.672904,
    "USDAFN":65.550003,
    "USDALL":122.239998,
    "USDAMD":473.959991,
    "USDANG":1.770403,
    "USDAOA":165.067001,
    "USDARS":15.250402,
    "USDAUD":1.304104,
    "USDAWG":1.79,
    "USDAZN":1.620604,
    "USDBAM":1.742204,
    "USDBBD":2,
    "USDBDT":78.430401,
    "USDBGN":1.752404,
    "USDBHD":0.377041,
    "USDBIF":1651,
    "USDBMD":1,
    "USDBND":1.362804,
    "USDBOB":6.860399,
    "USDZAR":13.710364,
    "USDZMK":5156.103593,
    "USDZMW":10.020363,
    "USDZWL":322.355011
  }
}

EDIT: store定义

Ext.define('CurrencyConvert.model.CurrencyCode', {
    extend : 'Ext.data.Model',
    pageSize: 0,
    fields : [
        {
            name : 'code',
            value : 'string'
        },
        {
            name : 'rate',
            value : 'float',
        }
    ]
});

不,商店正试图获得model,您定义为

model : 'CurrencyConvert.model.CurrencyCode',

如果你这样做,你必须在你的代码库的某个地方有一个这样的定义:

Ext.define('CurrencyConvert.model.CurrencyCode',
    extend:'Ext.data.Model',
    ...
});

,您必须已经加载了该文件。在99%的情况下,模型文件将放在app/model/CurrencyCode.js中,应用程序将具有名称CurrencyConvert,并且存储将包含requires

requires:[
    'CurrencyConvert.model.CurrencyCode'
]