本文介绍了从变量中选择一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Extjs中,我尝试从变量 c c b
$ b

我试过:

  var newStore = Store.data.items [0] .data.accrued; 

上面一个没有工作。我收到错误:

每当我添加 items [0] ,它使变量未定义。



当我检查:

  var newStore = Store.data.items.length; 

输出是: 0 //?



但是,如上图所示,可以看到 Store 变量中的项目。无论如何,我只想从变量 Store 中获取应计的价值。



我还检查了:

  var newStore = Store.data.items; 

输出是: []

解决方案

嗨Mr_Green你应该看看API有时是因为这是真的很直接;)

  Store.on('load',function(store,records){
records [0] .data.accrued;
}这个,{single:true})

更新 - 更深入



这个小字 将事件的侦听器应用于组件。它将适用于mixin 我应用的最后一个参数标识了这个监听器在调用一次后应该被删除。这对匿名听众很有用,因为你不能取消注册。



加载(这个,记录,成功,eOpts)



参数




  • this: Ext.data.Store

  • 记录: Ext.data.Model [] 记录数组

  • 成功:布尔值 如果操作成功,则为真。

  • eOpts:对象 >将选项对象传递给Ext.util.Observable.addListener。



所以records参数包含所有记录由当前加载操作返回。


In Extjs, I am trying to select a value accrued from a variable Store.

I tried:

var newStore = Store.data.items[0].data.accrued;

The above one is not working. I am getting error:

Whenever I add items[0], it is making the variable undefined.

When I checked:

var newStore = Store.data.items.length;

output is: 0 //?

But I can see that there are items in Store variable here as shown in the above image. Anyway, I just want to get the value of accrued from the variable Store.

I also checked:

var newStore = Store.data.items;

output is: [ ]

解决方案

Hey Mr_Green you should look into the API sometimes, cause this is really straight forward ;) Store load event

Store.on('load', function(store,records){
    records[0].data.accrued;
}, this, {single:true})

Update - a bit more in depth

The tiny word on applies a listener for a event to a component. It will be available for classes that mixin Ext.util.Observable where the last argument I applied identifies that this listener should get removed after it get called once. This is useful for anonymous listeners cause you cannot unregister them otherwise.

load( this, records, successful, eOpts )

Parameters

  • this : Ext.data.Store
  • records : Ext.data.Model[] An array of records
  • successful : Boolean True if the operation was successful.
  • eOpts : Object The options object passed to Ext.util.Observable.addListener.

So the records argument contains all the records that are returned by the current load operation.

这篇关于从变量中选择一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:02