javascript 如何动态更改 Ext js 存储数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32381349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change Ext js store data dynamically
提问by Surya Prakash Tumma
I have a combobox which looks like below
我有一个如下所示的组合框
{
xtype:'combo',
fieldLabel:'Test',
store:['a','b']
}
Without creating Ext store object I am assigning the array to store and it is displaying the values fine.
在不创建 Ext 存储对象的情况下,我将数组分配给存储,并且它显示的值很好。
At some action i want to update the store with ['d','e']
在某些操作中,我想用 ['d','e'] 更新商店
I have tried by assigning the new values to store like below
我尝试通过分配新值来存储,如下所示
comboObje.store=['d','e'];
but it is not updating the values.
但它没有更新值。
how to replace the orginal values with new values in the store.
如何用商店中的新值替换原始值。
回答by CD..
You can create a new store using bindStore
or just load new data to the existing store using loadData
:
您可以使用以下命令创建新商店bindStore
或仅将新数据加载到现有商店loadData
:
combo.store.loadData(['d', 'e'].map(function(item){ return [item]; }));
Working example: https://fiddle.sencha.com/#fiddle/tb1
回答by Tarabass
In version 5.* and higher you can use:
在 5.* 及更高版本中,您可以使用:
comboObje.setStore(['d','e']);
This doesn't work in previous versions.
这在以前的版本中不起作用。
Paste the following code into a Sencha Fiddleas a 'proof-of-concept':
将以下代码粘贴到Sencha Fiddle 中作为“概念验证”:
Ext.application({
name : 'Fiddle',
launch : function() {
var panel = Ext.create('Ext.form.Panel', {
title: 'test',
items: [{
xtype:'combo',
fieldLabel:'Test',
store:['a','b']
}],
renderTo: Ext.getBody()
});
panel.down('combo').setStore(['d','e']);
}
});
回答by Navaneeth-Kesavan
Try this:
试试这个:
comboObje.getStore().loadData([{'field1': 'd'}, {'field1': 'e'}]);
When you assign an array to 'store' config, ExtJS automatically generates field names.
当您将数组分配给“存储”配置时,ExtJS 会自动生成字段名称。