【问题标题】:Custom filter orderby自定义过滤器 orderby
【发布时间】:2016-05-27 21:01:27
【问题描述】:

我正在尝试构建一个自定义过滤器。在我的应用程序中,我有一些案例,我只想显示其中的一些。

    app.filter("noFnFilter", function () {
      return function (items) {

        if (items && items.length) {
            var returnVals = [];
            for (var i = 0; i < items.length; i++) {
                returnVals.push(items[i]);
                if (returnVals >= noFN ) {
                    return returnVals;
                }
                else {
                    return [];
                }


            }

            //returnVals.push(obj);
            // do some stuff

            return returnVals;
        }

    };
});

这些是一些情况,我希望过滤器仅显示 > 0 的“noFN”。

{
"SchemeCaseID": "122^254",
    "schemeid": "SA12 Part 2",
    "side": "LEFT",
    "malignancy": 5,
    "noParticipantsNormal": 491,
    "noParticipantsBenign": 33,
    "noParticipantsMalignant": 252,
    "noFN": 524,
    "noFP": -1,
    "noParticipants": 776,
    "rorecall": "Y",
    "caseid": 254
  },
  {
    "SchemeCaseID": "122^201",
    "schemeid": "SA12 Part 2",
    "side": "RIGHT",
    "malignancy": 3,
    "noParticipantsNormal": 91,
    "noParticipantsBenign": 160,
    "noParticipantsMalignant": 525,
    "noFN": 251,
    "noFP": -1,
    "noParticipants": 776,
    "rorecall": "Y",
    "caseid": 201
  },
  {
    "SchemeCaseID": "122^258",
    "schemeid": "SA12 Part 2",
    "side": "RIGHT",
    "malignancy": 4,
    "noParticipantsNormal": 145,
    "noParticipantsBenign": 103,
    "noParticipantsMalignant": 528,
    "noFN": 248,
    "noFP": -1,
    "noParticipants": 776,
    "rorecall": "Y",
    "caseid": 258
  },

很抱歉,我刚刚开始编码,非常感谢所有帮助。

【问题讨论】:

  • 由于您的问题的格式,很难确定您在问什么。你能重新格式化和完善你的问题吗?

标签: javascript angularjs filter


【解决方案1】:

我还没有测试过,但是这样的东西应该可以解决问题。

app.filter("noFnFilter", function () {
  return function (items) {

    if (items && items.length > 0) {
        var returnVals = [];
        for (var i = 0; i < items.length; i++) {
            if (items[i].noFN > 0 ) {
                returnVals.push(items[i]);
            }
        }
        return returnVals;
    } else {
        return [];
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 2014-10-18
    • 2016-04-17
    • 1970-01-01
    • 2011-01-24
    相关资源
    最近更新 更多