ExtJS:连接一个存储到一个组合框
ExtJS: Connecting a store to a combo box?
在下面的代码中,我手动向存储(称为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'
]
相关文章:
- 将一个组合框值传递给其他组合框
- 将多个表格作为一个组合表格提交
- 获取一个组合框值作为innerhtml
- extjs基于另一个组合框值过滤组合框
- 使用组合框填充另一个组合框,以便用户可以运行查询
- 如何根据另一个组合框的选定项目从数据库填充组合框中的项目
- Knob.js-有没有一种方法可以连接表盘,使它们有一个组合的总数
- 如何制作一个组合框,允许我根据选择显示数据
- 如何使用Javascript禁用在另一个组合框中选择的组合框的值
- 基于另一个组合框选择的自动填充组合框
- Browserify-require()一个组合字符串不会将模块构建到输出脚本中
- 如何在XPages CSJS中选择一个组合框值
- 是否有一种方法来放置一个树列在一个组合框
- 从组合框和文本输入字段中为另一个组合框赋值
- php、javascript和mysql如何连接到一个组合,如果点击,则通过另一个查询进入另一个组合
- ExtJS:连接一个存储到一个组合框
- ExtJS使一个组合项目不同
- 使用gulp-angular-templatecache创建一个组合HTML模板文件时,输出文件夹无效
- 通过更改第二个组合框来更新一个组合框
- 如何在HTML中使用另一个组合框来控制一个组合框