【发布时间】:2019-01-18 02:03:24
【问题描述】:
我正在尝试使用我的过滤器来处理我的ng-repeat。它没有像我希望的那样工作。我想知道是否不可能做我想做的事情?
我的html:
<input type="text" ng-model="search.text" class="form-control" id="search" placeholder="Search">
<div class='col-md-12' ng-repeat='(key,value) in cropplans | contains:search.text'> <h4> Title: key</h4>
</div>
这是我的控制器和过滤器:
aggriApp.filter('contains', function() {
return function(values, field) {
var result = {};
field = field.toLowerCase()
angular.forEach(values, function(key, value) {
if(value.company_name.toLowerCase().indexOf(field) >= 0){
result[key] = value
}
});
return result
编辑:当我在搜索输入中输入内容时,我应用的过滤器没有得到任何更改。如果搜索不匹配,我应该得到 0 个结果吧?
编辑:
$scope.cropplans 是一个类似于以下内容的对象:
Object
AkshaYagna: Array(1)
0:
$$hashKey: "object:2684"
active: true
area: "0.00000"
block: {id: 230, name: "default", farm: {…}}
certification: null
closing_reason: null
company_name: "AkshaYagna"
created: "2019-01-17T21:04:23.605311Z"
crop_forecast: [{…}]
estimated_cases_count: 2000
estimated_harvest_date: "2019-01-17"
estimated_harvest_date_end: "2019-02-28"
foodhub: 409
foodhub_seller: 3752
foodhub_transport_time: 0
id: 828
modified: "2019-01-17T21:04:23.605319Z"
planting_date: null
plu_code: {id: 12891, commodity: "Conventional Baby Bok Choy", variety: "Shanghai", size: "30#", package: "Cartons", …}
received_cases: null
received_on: null
user: {id: 4022, email: "asus@lenovo.com", first_name: "Child.farm", last_name: "06", telephone: null, …}
__proto__: Object
received: 0
length: 1
__proto__: Array(0)
Child.farm03: [{…}, received: 0]
Samuel Gibbs: (3) [{…}, {…}, {…}, received: 0]
shadow test: (2) [{…}, {…}, received: 0]
__proto__: Object
【问题讨论】:
-
有什么问题
-
已更新。基本上,过滤器不适用。假设我输入“farmer”,我希望 ng-repeat 适用于所有在 company_name 中带有“farmer”的项目都会显示?
-
你能提供你在 $scope.cropplans 中的内容吗
-
在编辑中添加。你知道吗。我认为这可能是因为该值是一个数组......但即使它是,如果我输入的内容不匹配,那么它应该返回空正确吗?
-
以 JSON 格式发布数组。 console.log($scope.cropplans) 的输出;
标签: angularjs filter angular-ui-bootstrap angularjs-filter