2016-10-22 7 views
0

これは以前に回答されていますが、それらの解決策のどれも私のために働いていません。いくつかの1つは、以下のエラーで私を助けてくれる?エラー:[filter:notarray]予想される配列ですが、受信しました

私は配列を取得していない午前とき、私はカスタムフィルタNG-繰り返しを使用して、エラーを取得しています。

誰も私が以下のようにServiceDisconnectsセクションを持っている場合

HTMLコードが

<td class="features" ng-show="list.Body.WorkOrder.OrderStatus.length > 0"> 
<span ng-repeat="indi in list.Body.Services.ServiceChanges.ServiceDisconnects.Service | filterWithOr:{_serviceID:['SS001','ST099','SS018']} ">{{indi._serviceID}},{{indi.EPCServiceDef.EPCProduct._pn}}<br></span> 
</td> 

エラーが生成されますJSONObjectとJSONArray

の両方のために処理しますngのリピートを使用するコントローラとcomeupために私を助けることができます

"ServiceDisconnects": { 
    "Service": { 
    "-serviceID": "ST099", 
    "ServiceChangeActivity": "Disconnect", 
    "TelephoneNumbers": { 
     "TN": "     " 
    }, 
    "Rate": "0.00", 
    "Desc": "Xhnoecosvr", 
    "Count": "0", 
    "LOB": "Other", 
    "PackageCode": "ST099 ", 
    "EPCServiceDef": { 
     "EPCProduct": { 
     "-pn": "10400138", 
     "Name": "EcoSaver Opt-Out Tracking", 
     "LongDescription": "NO ECOSAVER TRACKING", 
     "Type": "Feature", 
     "LOB": "Video" 
     } 
    }, 
    "CSGServiceIdentifier": "5" 
    } 
} 

ServiceDisconnectsセクションにmultがある場合も同じことが動作しますipleサービス配列。ここで

は、カスタムフィルタ

app.filter('filterWithOr', function($filter) { 
    var comparator = function(actual, expected) { 
     if (angular.isUndefined(actual)) { 
      // No substring matching against `undefined` 
      return false; 
     } 
     if ((actual === null) || (expected === null)) { 
      // No substring matching against `null`; only match against `null` 
      return actual === expected; 
     } 
     if ((angular.isObject(expected) && !angular.isArray(expected)) || (angular.isObject(actual) && !hasCustomToString(actual))) { 
      // Should not compare primitives against objects, unless they have custom `toString` method 
      return false; 
     } 

     actual = angular.lowercase('' + actual); 
     if (angular.isArray(expected)) { 
      var match = false; 
      expected.forEach(function(e) { 
       e = angular.lowercase('' + e); 
       if (actual.indexOf(e) !== -1) { 
        match = true; 
       } 
      }); 
      return match; 
     } else { 
      expected = angular.lowercase('' + expected); 
      return actual.indexOf(expected) !== -1; 
     } 
    }; 
    return function(campaigns, filters) { 
     return $filter('filter')(campaigns, filters, comparator); 
    }; 
}); 

答えて

1

である私はあなただけの記事でjsonのサブセットを見せていると仮定していますか?

jsonのServiceプロパティはオブジェクトであり、配列ではありません。オブジェクトのプロパティを反復するには、あるng-repeatの他のフォームを使用する必要があります:また、あなたが扱っていないので、それらの変更を反映するために、あなたのfilterWithOrフィルタを更新したいとしている

<div ng-repeat="(key, value) in myObj"></div> 

アレイ。 (key, value)

The JavaScript specification does not define the order of keys returned for an object, so Angular relies on the order returned by the browser when running for key in myObj. Browsers generally follow the strategy of providing keys in the order in which they were defined, although there are exceptions when keys are deleted and reinstated. See the MDN page on delete for more info.

ngRepeat will silently ignore object keys starting with $, because it's a prefix used by Angular for public ($) and private ($$) properties.

The built-in filters orderBy and filter do not work with objects, and will throw an error if used with one.

+0

FIは答えに同意するが、私は私がするのでJSONObjectとJSONArrayの両方のためにNG・リピートを使用するのに役立ちますどのコントローラできるソリューションがあるを使用してng-repeat Angular docsに応じて注意すべき事柄の

カップル私のJSONデータは何度か配列として来て、いつかはObject – Batman

関連する問題