简体   繁体   English

如何使用ExtJS访问从JsonStore提取的值?

[英]How to access a value fetched from a JsonStore with ExtJS?

In the following JS code, I am trying to read json data from url: 在以下JS代码中,我尝试从url读取json数据:

// Create JsonStore
var storeED = new Ext.data.JsonStore({                    
            url: './wfServlet?workd=' + workd
                + '&type=detail' + '&status=' + status +'&userName='+userName,
            root: 'root',
            fields: [{name:'ERROR_DESC'}]
            });

then I want to get the value from the field ERROR_DESC . 那么我想从ERROR_DESC字段获取值。

Ext.getCmp('errorMessage').setValue(storeED.ERROR_DESC);// want  to read value

The code just above doesn't work for me. 上面的代码对我不起作用。
What am I missing ? 我想念什么?

Stores don't have values. 商店没有价值。 Stores are caches of Ext.data.Model instances, which are what hold values which are mapped to the fields defined for the Model which is applied to the Store. 商店是Ext.data.Model实例的缓存,这些实例保存将值映射到为应用到商店的Model定义的字段的值。

To accomplish what you're trying to do, you'll need to access the instance of the Model inside your store which contains the record data you desire, such as storeEd.getAt(0) , assuming you only have one model instance in your store's cache. 要完成您想做的事情,您需要访问商店内的Model实例,其中包含您想要的记录数据,例如storeEd.getAt(0) ,假设您的实例中只有一个模型实例商店的缓存。

If this is the only field AND you only expect one instance to live within this store, it might be better to not even bother with a store at all. 如果这是唯一的字段,并且您只希望一个实例存在于该商店中,那么最好甚至不要去理会商店。 You could either add a proxy to the Model itself, or just use the value returned from a regular Ext.Ajax.request . 您可以向模型本身添加代理,也可以仅使用常规Ext.Ajax.request返回的值。 If you don't plan on using this value beyond this particular usage, a store is probably unnecessary. 如果您不打算在此特定用途之外使用此值,则可能不需要存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM