0

Basically I try to match a transaction with a category. I send the transaction title to a function and if there is category that contains a keyword with the same transaction title then return the category id. But it doesn't work!

What is wrong?

$scope.data.push({
                title: temp[2],
                category: matchForCategory(temp[2]) 
            });

    //Try to match a transaction with a category
    function matchForCategory(transactionTitle){
        var temp = 0;

        angular.forEach($scope.categories, function(c){
            angular.forEach(c.keywords, function(k){
               if(k == transactionTitle)
                        temp =c.id;
            });
        });

        console.log(temp); //Output is always: 0

        if(temp == 0)
            return 'NA';
        else
            return temp;
    }

categories is as follow:

[...,{
    "id": 13,
    "title": "Utemat",
    "keywords": [
      "MCDONALD S VASAG",
      "PIZZERIA AMORE",
      "BISTRO65"
    ],
    "$$hashKey": "00T"
  },
  {
    "id": 14,
    "title": "Natklubb",
    "keywords": [

    ],
    "$$hashKey": "00V"
  },...]
4

1 回答 1

0

是否可能是大小写不匹配?尝试:

(k.toUpperCase() === transactionTitle.toUpperCase())
于 2013-06-14T21:23:06.983 回答