我试图通过filter1 AND filter2 AND filter3进行过滤。一切都有效,除了我的ng-click属性。我不清楚语法应该如何根据需要使这个示例函数。
以下是示例的链接:http://jsfiddle.net/40vrs6db/
<div ng-app ng-controller="MainController">
<div ng-repeat="strain in strainsFound = (strains | filter:{name: strain_name, storesThatHaveIt:strain_storesThatHaveIt, tod:strain_tod})">
<div>
<p data-t="{{strain.storesThatHaveIt}}">{{strain.name}}</p>
<p>{{strain.tod}}</p>
</div>
</div>
<select ng-model="strain_tod">
<option value="morning">Morning</option>
<option value="afternoon">Afternoon</option>
<option value="evening">Evening</option>
<option value="night">Night</option>
</select>
<div ng-model="strain_storesThatHaveIt">
<a ng-click="Hastings">Hastings</a>
<a ng-click="Kingsway">Kingsway</a>
<a ng-click="Quebec">Quebec</a>
<a ng-click="Ontario">Ontario</a>
</div>
<input ng-model="strain_name" />
</div>
function MainController($scope) {
$scope.strain_name = "";
$scope.strain_storesThatHaveIt = "";
$scope.strain_tod = "";
$scope.strains = [{
"storesThatHaveIt": ["Hastings", "Ontario", "Kingsway"],
"name": "rub",
"tod": ["night"]
}, {
"storesThatHaveIt": ["Hastings"],
"name": "shatter",
"tod": ["evening", "night"]
}, {
"storesThatHaveIt": ["Kingsway"],
"name": "sour diesel",
"tod": ["morning", "afternoon", "evening"]
}, {
"storesThatHaveIt": ["Hastings", "Quebec"],
"name": "m39",
"tod": ["morning", "afternoon"]
}]
}
答案 0 :(得分:0)
感谢Petr Averyanov,我现在有了答案:
<div ng-app ng-controller="MainController">
<div ng-repeat="strain in strainsFound = (strains | filter:{name: strain_name, storesThatHaveIt:strain_storesThatHaveIt, tod:strain_tod})">
<div>
<p data-t="{{strain.storesThatHaveIt}}">{{strain.name}}</p>
<p data-t="{{strain.storesThatHaveIt}}">{{strain.tod}}</p>
</div>
</div>
<select ng-model="strain_tod">
<option value="morning">Morning</option>
<option value="afternoon">Afternoon</option>
<option value="evening">Evening</option>
<option value="night">Night</option>
</select>
<div>
<a ng-click="strain_storesThatHaveIt = 'Hastings'">Hastings</a>
<a ng-click="strain_storesThatHaveIt = 'Kingsway'">Kingsway</a>
<a ng-click="strain_storesThatHaveIt = 'Quebec'">Quebec</a>
<a ng-click="strain_storesThatHaveIt = 'Ontario'">Ontario</a>
</div>
<input ng-model="strain_name" />
</div>
<script>
function MainController($scope) {
$scope.strain_name = "";
$scope.strain_storesThatHaveIt = "";
$scope.strain_tod = "";
$scope.strains = [{
"storesThatHaveIt": ["Hastings", "Ontario", "Kingsway"],
"name": "rub",
"tod": ["night"]
}, {
"storesThatHaveIt": ["Hastings"],
"name": "shatter",
"tod": ["evening", "night"]
}, {
"storesThatHaveIt": ["Kingsway"],
"name": "sour diesel",
"tod": ["morning", "afternoon", "evening"]
}, {
"storesThatHaveIt": ["Hastings", "Quebec"],
"name": "m39",
"tod": ["morning", "afternoon"]
}]
}
</script>