Javascript 具有多个过滤器选项的角度ng重复
我有以下JSON数据:Javascript 具有多个过滤器选项的角度ng重复,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,我有以下JSON数据: { "doorTypes": [ { "name": "Flat Panel", "image": "doors/flatpanel.png", "type": "Wood" }, { "name": "Raised Panel", "image": "doors/raisedpanel.png", "type": "Wood" }, { "name": "Slab Door", "i
{
"doorTypes": [
{
"name": "Flat Panel",
"image": "doors/flatpanel.png",
"type": "Wood"
},
{
"name": "Raised Panel",
"image": "doors/raisedpanel.png",
"type": "Wood"
},
{
"name": "Slab Door",
"image": "doors/slabdoor.png",
"type": "Wood"
}],
"woods": [
{
"name": "Alder",
"image": "species/alder.png",
"weights":[
{
"name": "Flat Panel",
"weight": 1.19
},
{
"name": "Raised Panel",
"weight": 1.76
},
{
"name": "Slab Door",
"weight": 1.97
}]
},
{
"name": "Ash",
"image": "species/ash.png",
"weights":[
{
"name": "Flat Panel",
"weight": 1.7
}]
},
{
"name": "Bamboo",
"image": "species/bamboo.png",
"weights":[
{
"name": "Slab Door",
"weight": 2.7
}]
},
{
"name": "Beech",
"image": "species/beech.png",
"weights":[
{
"name": "Raised Panel",
"weight": 2.27
},
{
"name": "Slab Door",
"weight": 2.54
}]
}]
}
根据您选择的doorType
,我想过滤wood
类型。例如,如果选择凸起面板
,我只希望显示具有凸起面板
权重的木材。所以在这种情况下,Alder和Beech
会显示,而不是Ash
或bambol
现在我严格使用ng repeat,它显示所有的木材类型。我已经查看了docs for ng过滤器,但我不确定如何在权重
对象具有多个属性的情况下应用它
我现在要说的是:
<ul class="touchcarousel-container">
<li class="touchcarousel-item" ng-repeat="obj in currentObject">
<div class="img-select" ng-click="setActive(this)" ng-class="{itemSelected : isActive(this)}">
<div align="center">
<img ng-src="resources/images/aventos/{{obj.image}}" />
</div>
<div class="img-title">{{obj.name}}</div>
</div>
</li>
</ul>
-
{{obj.name}
如果更改JSON更有意义,我也愿意这样做
编辑
这就是我的解决方案:
<li class="touchcarousel-item" ng-repeat="obj in currentObject" ng-show="woodTypes(obj)">
然后:
$scope.woodTypes = function(obj)
{
var shown = false;
for (var i = 0; i < obj.weights.length; i++)
{
if (obj.weights[i].name == $scope.cabinetDetails.door.name)
{
shown = true;
break;
}
}
return shown;
}
$scope.woodTypes=函数(obj)
{
显示的var=假;
对于(变量i=0;i
尝试编写一个自定义过滤器,并使用类似这样的组合
<select ng-options="foo.blah for foo in foos" ng-model="selection"></select>
<li ng-repeat="obj in objects|filter:selection|filterFunction">{{obj}}</li>
.filter('filterFunction', function() {
return function (objects) {
var filter_objects = [];
for (var i = 0; i < objects.length; i++) {
for (var j = 0; j < objects[i].weights.length; j++) {
if (objects[i].weights[j].name === "Raised Panel") {
filter_objects.push(objects[i]);
}
}
}
return filter_objects;
}
});
{{obj}
.filter('filterFunction',function(){
返回函数(对象){
var filter_objects=[];
对于(var i=0;i
尝试编写一个自定义过滤器,并使用类似这样的组合
<select ng-options="foo.blah for foo in foos" ng-model="selection"></select>
<li ng-repeat="obj in objects|filter:selection|filterFunction">{{obj}}</li>
.filter('filterFunction', function() {
return function (objects) {
var filter_objects = [];
for (var i = 0; i < objects.length; i++) {
for (var j = 0; j < objects[i].weights.length; j++) {
if (objects[i].weights[j].name === "Raised Panel") {
filter_objects.push(objects[i]);
}
}
}
return filter_objects;
}
});
{{obj}
.filter('filterFunction',function(){
返回函数(对象){
var filter_objects=[];
对于(var i=0;i
正在更改订单的签出。我需要它们不要出现,这就是为什么我认为我需要一个过滤器
而不是orderBy
啊,对不起,我误解了。这只是改变了顺序。我需要它们不要出现,这就是为什么我认为我需要一个过滤器
而不是orderBy
啊,对不起,我误解了。我想出了一个(我认为是)更简单的解决方案,请参阅我上面的编辑。我尝试了一些与您上面的解决方案非常相似的方法,但我无法使其发挥作用。+1然而,为了您的支持,我想出了(我认为是)一个更简单的解决方案,请参阅我上面的编辑。我尝试了与您的上述解决方案非常相似的方法,但未能使其发挥作用。,+1不过,感谢您的支持