Skip to content Skip to sidebar Skip to footer

Select A Value From A Variable

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:

Solution 1:

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 : BooleanTrue if the operation was successful.
  • eOpts : ObjectThe options object passed to Ext.util.Observable.addListener.

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

Solution 2:

Store loading is asynchronous. When you are logging, the values aren't loaded yet.

The console always shows the most up to date version of the object. You need to listen to the store load event.

Post a Comment for "Select A Value From A Variable"