在 ngRepeat 中筛选嵌套属性
Filtering Nested Properties in ngRepeat
在我的控制器中,我有:
$scope.currentDiscount = new DiscountPrototype;
哪里:
var DiscountPrototype = function(){
this.Id = 0;
this.PromoCode = null;
this.DiscountValue = null;
this.DiscountProducts = []
}
var DiscountProductPrototype = function(discountId,id,catId,catType,name) {
this.DiscountId = discountId;
this.ProductCategoryType = catType;
this.Name = name
}
然后我把一堆新的DiscountProductPrototypes推到$scope.currentDiscount的DiscountProducts数组中。如果折扣产品具有产品类别类型 = "C",则它是一个类别,如果它是"P",则它是一个产品。我的过滤器打算只显示折扣产品数组中作为类别的对象。
<div ng-repeat="category in currentDiscount.DiscountProducts | filter:{category.ProductCategoryType: 'C' : true}"
class="productTile">
<p>{{category.Name}}</p>
</div>
使用上面的过滤器,我得到以下错误:
Syntax Error: Token '.' is at column {2} of the expression [{3}] starting at [{4}].
这似乎说有问题:
category.ProductCategoryType
如果我执行以下操作,则不会出错,但过滤器不执行任何操作。将显示类别和产品。
<div ng-repeat="category in currentDiscount.DiscountProducts | filter: category.ProductCategoryType='C'"
class="productTile">
是否需要创建自定义筛选器才能实现此类筛选?
这应该有效:
<div ng-repeat="category in currentDiscount.DiscountProducts | filter:{ProductCategoryType: 'C'}"
class="productTile">
<p>{{category.Name}}</p>
</div>
问题在于true
单词的位置。 true
必须放在第二个冒号之后。在第一个冒号之后,它应该只是Expression
.
尝试以下...
<div ng-repeat="category in currentDiscount.DiscountProducts | filter:{ProductCategoryType: 'C'}: true"
class="productTile">
<p>{{category.Name}}</p>
</div>
有关筛选器的详细信息,请参阅:https://docs.angularjs.org/api/ng/filter/filter
相关文章:
- 访问键中包含空格的嵌套属性
- 如何将id数组与带下划线的对象数组嵌套属性进行比较
- 正在检查对象javascript中是否存在嵌套属性
- 更新JavaScript对象中的嵌套属性
- 使用 jQuery 传递的 Rails 嵌套属性
- 如何迭代json对象的嵌套属性并创建新的数组列表
- 如何正确传递具有排列属性的嵌套属性?(JSX)
- 如何动态获取对象的嵌套属性
- AngularJS - 包含嵌套属性指令的内容
- 嵌套属性作为函数参数
- 猫鼬:嵌套属性上为空
- 如何检查主干模型中的嵌套属性是否已更改
- 在 ngRepeat 中筛选嵌套属性
- 筛选器深层嵌套属性返回空数组
- 支持流星和铁路由器中具有嵌套属性的多个参数
- 主干虹吸嵌套属性
- 访问 JavaScript 中的嵌套属性
- 在 AJAX 响应中查找嵌套属性,这是 try/catch 的情况
- 从嵌套属性数组中获取对象嵌套值
- JQuery,从嵌套属性中访问对象的根属性