在AngularJS中,可以使用filter
过滤器来按照字段在数组中进行过滤。以下是一个示例解决方案:
HTML模板:
Name
Age
{{person.name}}
{{person.age}}
AngularJS控制器:
angular.module("myApp", [])
.controller("myController", function($scope) {
$scope.people = [
{name: "John", age: 25},
{name: "Jane", age: 30},
{name: "Bob", age: 35},
{name: "Alice", age: 40}
];
});
在上述示例中,ng-model="searchText"
绑定了输入框的值,该值将用于过滤数组。filter:searchText
将根据输入框的值来过滤people
数组中的元素。只有包含输入框的值的字段将被显示在表格中。
请注意,这只是一个简单的示例,你可以根据自己的需求进行修改和扩展。
上一篇:按照字段列表检索对象列表的方法
下一篇:按照字段值降序对列表进行排序