Search code examples
jsonextjsstore

Finding out how many status objects are in a store


I have a store called CreativeStore and inside one of the fields is Status. The data is sent as JSON. I created a variable that is getting the Creative store. How would I find out what the status is and how many statuses their are.
In my Creative Model I have a field

 }, {
    type: 'int',
    name: 'Status'
  }, {

In my View Controller I have a method that checks if the store I created for the Creative Model exists (It does) and I assign it to a var called test.

var test = this.getCreativeStore();

  getCreativeStore: function () {
    var creativeStore = this.getStore('creativeStore');
    if (!creativeStore) {
      this.logError('creativeStore is undefined');
    }
    return creativeStore;
  }

How do I find out how many Statuses are in the variable test?


Solution

  • You can use collect:

    Collects unique values for a particular dataIndex from this store.

    For example:

    test.collect('status').length;