我想过滤一个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