且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用角度JS过滤器格式的值在数组

更新时间:2023-11-26 20:22:34

货币过滤器适用于单个值。如果你想应用到阵列的过滤器,你需要添加你自己的,如:

The currency filter applies to a single value. If you want a filter that applies to an array, you need to add your own, such as:

angular.module('yourModule')
.filter('currenyArray', function($filter) {
  return function(input, uppercase) {
    input = input || [];
    var out = [];
    for (var i = 0; i < input.length; i++) {
      out.push($filter('currency')(input[i]))
    }
    return out;
  };
})

然而,这会返回一个数组。如果你想要写的数组,你需要适应的函数来计算字符串而不是一个数组。

However this will return an array. If you do want to write the array, you need to adapt the function to compute a string instead of an array.