【问题标题】:Finding out how many status objects are in a store找出商店中有多少状态对象
【发布时间】:2016-07-21 21:42:27
【问题描述】:

我有一家名为CreativeStore 的商店,其中一个字段是Status。数据以 JSON 格式发送。我创建了一个获取创意商店的变量。我如何知道状态是什么以及它们有多少状态。
在我的创意模型中,我有一个字段

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

在我的视图控制器中,我有一个方法可以检查我为创意模型创建的商店是否存在(确实存在),然后我将它分配给一个名为 test 的 var。

var test = this.getCreativeStore();

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

如何找出变量测试中有多少个状态?

【问题讨论】:

  • 不太清楚你在问什么。您是否希望引入一组独特的所有状态字段?
  • 如果您只需要该商店中的记录数test.getCount() 应该这样做。如果您需要不同的计数,您将不得不应用一些可能使用 test.each() 的逻辑
  • test.getCount()Ext.Array.unique(test.getRange().map(function(record) {return record.get("Status")}).length

标签: json extjs store


【解决方案1】:
var statusCount = 0;

test.each(function(record) {
    // Your status value in myStatus
    if(record.get('Status') === myStatus)
        ++statusCount;
});

【讨论】:

    【解决方案2】:

    你可以使用collect:

    从该商店收集特定 dataIndex 的唯一值。

    例如:

    test.collect('status').length;
    

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 2022-08-19
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多