我想過濾一個JSON數組。在我的例子中,JSON數組的值是過濾JSON與angularjs
vm.users = [{ "fname": "Antoan", "lname": "Jonson", "Address": "Address1" }, ... ]
如何以姓氏開頭(例如'Jo')?我厭倦了這樣:
angular.module('MyApp', ['ngMaterial', 'ngMessages', ])
.controller('AdminController', function ($scope, $http, $filter, $location, $sce) {
MyApp.filter('myFilter', function() {
return function (input, term) {
var output = [];
angular.forEach(input, function (value, index) {
if (value.lname.startsWith(term)) {
output.push(value);
}
});
return output;
}
});
});
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array叫它/過濾器 – str