In the below code, I manually add records to a store(called dataStore
). But when I try to load the store to a combo box(labeled cmb
), I get the following error:
http://localhost:1841/CurrencyConvert.model.CurrencyCode?_dc=147hj_126&query=&page=1&start=0&limit=25 404 (Not Found)
It appears as if the store is trying to call the proxy to load data(even though it has all the data already, manually loaded by me). Following is the store:
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
});
}
});
And Ajax request where the store is being used:
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);
},
});
Following is sample data I am fetching:
{
"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: The store definition
Ext.define('CurrencyConvert.model.CurrencyCode', {
extend : 'Ext.data.Model',
pageSize: 0,
fields : [
{
name : 'code',
value : 'string'
},
{
name : 'rate',
value : 'float',
}
]
});
No, the store is trying to get the model
, which you defined as
model : 'CurrencyConvert.model.CurrencyCode',
if you do so, you have to have somewhere in your codebase a definition like this:
Ext.define('CurrencyConvert.model.CurrencyCode',
extend:'Ext.data.Model',
...
});
and you will have to have loaded that file. In 99% of the cases, the model file would be placed in app/model/CurrencyCode.js
, the application would have the name CurrencyConvert
, and the store would contain a requires
section
requires:[
'CurrencyConvert.model.CurrencyCode'
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.