【问题标题】:Loop through a spreadsheet and count unique rows in jQuery循环遍历电子表格并计算 jQuery 中的唯一行数
【发布时间】:2015-04-15 08:02:26
【问题描述】:

我有一个电子表格,其中包含用户(在不同商店)使用我的应用程序进行的签到。人们可以在一家商店多次登记入住。我已经有一个循环来计算所有签到(参见下面的示例)。我想要的是一个循环来计算所有唯一的签到。如何在 jQuery 中做到这一点?

$.getJSON(url, function(data) {
    for (var i = 0; i < data.feed.entry.length; i++) {
      if(data.feed.entry[i].gsx$store.$t == storeName) {
        numberOfCheckIns++;
      }
    }
  });

编辑: 让我具体说明问题。 我的记录是这样的:

id | timecheckedin | points | store | user

我想统计在商店“foo”签到的所有唯一用户

【问题讨论】:

  • 让问题更具体

标签: jquery json unique rows spreadsheet


【解决方案1】:

我自己已经做过了。如果有更有效的方法,请随时发表评论。

$.getJSON(url, function(data) {
  $.each(data.feed.entry, function (index, value) {
    if (value.gsx$store.$t == storeName) {
      if($.inArray(value.gsx$user.$t, uniqueNames) === -1) {
            uniqueNames.push(value.gsx$user.$t);
      }
        numberOfCheckIns++;
      }     
    });
      amountOfUniqueFans = uniqueNames.length;
});     

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-03
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多