自定义过滤器orderby

时间:2016-02-16 14:21:04

标签: javascript angularjs filter

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

    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;
        }

    };
});

这些是一些情况,我希望过滤器只显示&#34; noFN&#34;那是&gt; 0

{
"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
  },

对不起,我刚刚开始编码,所有的帮助都非常感谢。

1 个答案:

答案 0 :(得分:0)

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

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 [];
    }
};