设置extjs 6组合框's在运行时存储数据会导致显示错误
Setting an extjs 6 combobox's store data at runtime results in display error
我有一个组合框的原型,我试图在运行时设置存储数据。
当我尝试这样做时,组合框下的菜单不会渲染(或者它渲染得太小以至于你实际上看不到它)。它在这里的sencha小提琴:
Ext.define('ComboBoxRates',{
extend: 'Ext.data.Store',
alias: 'store.rates',
storeId: 'ratescombo',
fields: ['rate', 'description', 'price' ]
});
Ext.define('ComboPanel',{
extend: 'Ext.panel.Panel',
title: 'Test',
renderTo: Ext.getBody(),
items:[
{
xtype: 'combobox',
editable: false,
displayField: 'description',
valueField: 'price',
}
]
});
Ext.application({
name : 'Fiddle',
launch : function() {
var data = [
{
description: "$105: Standard Registration",
price: "105",
rate: "rate1"
},
{
description: "$125: Non-Member Rate",
price: "125",
rate: "rate2"
},
{
description: "$44: Price for SK tester",
price: "44",
rate: "rate3"
},
{
description: "$11: Another price :O",
price: "11",
rate: "rate5"
}
];
var rates = Ext.create('ComboBoxRates');
rates.setData(data);
// Showing data is loaded into the store
console.group('directly from store instance');
rates.each(function (rate){
console.log(rate.getData());
});
console.groupEnd();
var panel = Ext.create('ComboPanel');
panel.down('combobox').setStore(rates);
// Showing that the data is definitely in the widget's store
console.group('from widget store');
panel.down('combobox').getStore().each(function (rate){
console.log(rate.getData());
});
console.groupEnd();
}
});
我知道数据被加载到combobox的存储中(在fiddle中打开控制台日志),所以我不确定为什么它没有正确渲染。
我知道在这种情况下这看起来很傻,但原型是从网格的小部件列中提取的逻辑,其中每行都有不同的存储数据。
我还构建了一个后退一步的原型,该原型具有相同的结构,但相同的数据被内联在商店的定义中,这很有效:
Ext.define('ComboBoxRates',{
extend: 'Ext.data.Store',
alias: 'store.rates',
storeId: 'ratescombo',
fields: ['rate', 'description', 'price' ],
data: [
{
description: "$105: Standard Registration",
price: "105",
rate: "rate1"
},
{
description: "$125: Non-Member Rate",
price: "125",
rate: "rate2"
},
{
description: "$44: Price for SK tester",
price: "44",
rate: "rate3"
},
{
description: "$11: Another price :O",
price: "11",
rate: "rate5"
}
]
});
Ext.define('ComboPanel',{
extend: 'Ext.panel.Panel',
title: 'Test',
renderTo: Ext.getBody(),
items:[
{
xtype: 'combobox',
editable: false,
displayField: 'description',
valueField: 'price',
}
]
});
Ext.application({
name : 'Fiddle',
launch : function() {
var rates = Ext.create('ComboBoxRates');
var panel = Ext.create('ComboPanel');
panel.down('combobox').setStore(rates);
}
});
我以为updateLayout可以解决这个问题,但事实并非如此。
我的代码有问题吗?有没有办法在运行时设置组合框的值?
如果缺少queryMode
,请在组合中使用queryMode: 'local'
。
工作示例:https://fiddle.sencha.com/#fiddle/10al
相关文章:
- 如何有效地将游戏数据存储在URL查询字符串中
- 将数据存储在javascript数组中以供进一步使用
- 将数据存储到元素中
- 如何将变量数据存储在其他变量中并对其进行解析
- 将新类实例中的数据存储在数组中
- 如何在Java Script中比较二维数组和一维数组,并将常见数据存储在另一个数组中
- 组合框是否需要数据存储
- 将动态feild数据存储到jquery-mobile和php-mysql中的数据库中
- 将数据存储在请求与请求中
- 将json数据存储在sqlite(phonegap应用程序)中
- 如何给$('inputs')每个函数,以将数据存储为 asp.net 中的键值对
- 使用 Ajax 将 PHP 嵌入到 JavaScript 中,以便将 MySQL 数据存储在 JavaScript 对象
- 无法将数据存储到 mongoDB
- Ext JS - 将面板绑定到数据存储的最佳方法
- 如何将数据存储值传递给javascript?我需要从gae数据存储中获取数据,并需要传递javascript
- 在数组数组中查找表数据存储
- 客户端数据存储
- 如何使用javascript将数据存储到mysql数据库中
- ServiceWorker数据存储在哪里
- Javascript Security:将敏感数据存储在比cookie更安全的自调用函数中