Javascript 如何根据单击的复选框过滤JSON?
我的javascript中有一个简单的JSON对象,我希望在单击按钮时对其进行过滤 我环顾四周,发现了这个。到目前为止,我有:Javascript 如何根据单击的复选框过滤JSON?,javascript,jquery,angularjs,checkbox,angularjs-ng-repeat,Javascript,Jquery,Angularjs,Checkbox,Angularjs Ng Repeat,我的javascript中有一个简单的JSON对象,我希望在单击按钮时对其进行过滤 我环顾四周,发现了这个。到目前为止,我有: $scope.myFunc = function(a) { for(meal in $scope.mealTypes){ var t = $scope.mealTypes[meal]; if(t.on && a.type.indexOf(t.name) > -1){
$scope.myFunc = function(a) {
for(meal in $scope.mealTypes){
var t = $scope.mealTypes[meal];
if(t.on && a.type.indexOf(t.name) > -1){
return true;
}
}
};
$scope.mealTypes = {Breakfast: false, mainMeal:false};
这是我的HTML:
<input id="checkBox" type="checkbox" name="Breakfast" value="Breakfast" data-ng-model="mealTypes.breakfast">
<input id="checkBox" type="checkbox" name="mainmeal" value="Main Meal" data-ng-model="mealTypes.mainMeal">
基本上,我的目标是在按下div时在其上显示复选框值并过滤数组。我该怎么做?这符合你的问题。基本上,它使用OR操作过滤单击复选框。您需要修改此答案以适应您的数据和目的
核心代码是:
angular.module('myFilters', []).
filter('bygenre', function() {
return function(movies,genres) {
var out = [];
// Filter logic here, adding matches to the out var.
return out;
}
});
这是同样的答案。这适合你的问题。基本上,它使用OR操作过滤单击复选框。您需要修改此答案以适应您的数据和目的
核心代码是:
angular.module('myFilters', []).
filter('bygenre', function() {
return function(movies,genres) {
var out = [];
// Filter logic here, adding matches to the out var.
return out;
}
});
这是同样的答案。这适合你的问题。基本上,它使用OR操作过滤单击复选框。您需要修改此答案以适应您的数据和目的
核心代码是:
angular.module('myFilters', []).
filter('bygenre', function() {
return function(movies,genres) {
var out = [];
// Filter logic here, adding matches to the out var.
return out;
}
});
这是同样的答案。这适合你的问题。基本上,它使用OR操作过滤单击复选框。您需要修改此答案以适应您的数据和目的
核心代码是:
angular.module('myFilters', []).
filter('bygenre', function() {
return function(movies,genres) {
var out = [];
// Filter logic here, adding matches to the out var.
return out;
}
});
这是相同的选项。首先,它们应该是单选按钮,而不是复选框
<div ng-controller="HelloCntl" ng-init="type='Breakfast'">
Breakfast
<input id="radio" type="radio" data-ng-model="type" ng-value="'Breakfast'"/>
Main Meal
<input id="radio" type="radio" data-ng-model="type" ng-value="'Main Meal'"/>
<div ng-repeat="rec in reciepes| filter : type">
<div> {{rec}}</div>
</div>
早餐
主食
{{rec}}
试试上面的方法,希望能奏效。首先,它们应该是单选按钮,而不是复选框
<div ng-controller="HelloCntl" ng-init="type='Breakfast'">
Breakfast
<input id="radio" type="radio" data-ng-model="type" ng-value="'Breakfast'"/>
Main Meal
<input id="radio" type="radio" data-ng-model="type" ng-value="'Main Meal'"/>
<div ng-repeat="rec in reciepes| filter : type">
<div> {{rec}}</div>
</div>
早餐
主食
{{rec}}
试试上面的方法,希望能奏效。首先,它们应该是单选按钮,而不是复选框
<div ng-controller="HelloCntl" ng-init="type='Breakfast'">
Breakfast
<input id="radio" type="radio" data-ng-model="type" ng-value="'Breakfast'"/>
Main Meal
<input id="radio" type="radio" data-ng-model="type" ng-value="'Main Meal'"/>
<div ng-repeat="rec in reciepes| filter : type">
<div> {{rec}}</div>
</div>
早餐
主食
{{rec}}
试试上面的方法,希望能奏效。首先,它们应该是单选按钮,而不是复选框
<div ng-controller="HelloCntl" ng-init="type='Breakfast'">
Breakfast
<input id="radio" type="radio" data-ng-model="type" ng-value="'Breakfast'"/>
Main Meal
<input id="radio" type="radio" data-ng-model="type" ng-value="'Main Meal'"/>
<div ng-repeat="rec in reciepes| filter : type">
<div> {{rec}}</div>
</div>
早餐
主食
{{rec}}
请尝试上面的方法,希望这能奏效。或者,您可以使用复选框将数据模型项标记为选中或未选中,并基于此标记显示它们。下面是我举的一个例子:
<label ng-repeat="meal in recipes">{{meal.type}}
<input id="checkBox" ng-model="meal.selected" type="checkbox"/>
</label>
<div ng-repeat='meal in recipes' ng-show="meal.selected">
<h3>{{meal.type}}</h3>
<p>{{meal.description}}</p>
</div>
{{mean.type}
{{MEIN.type}
{{mean.description}}
或者,您可以使用复选框将数据模型项标记为选中或未选中,并基于此标记显示它们。下面是我举的一个例子:
<label ng-repeat="meal in recipes">{{meal.type}}
<input id="checkBox" ng-model="meal.selected" type="checkbox"/>
</label>
<div ng-repeat='meal in recipes' ng-show="meal.selected">
<h3>{{meal.type}}</h3>
<p>{{meal.description}}</p>
</div>
{{mean.type}
{{MEIN.type}
{{mean.description}}
或者,您可以使用复选框将数据模型项标记为选中或未选中,并基于此标记显示它们。下面是我举的一个例子:
<label ng-repeat="meal in recipes">{{meal.type}}
<input id="checkBox" ng-model="meal.selected" type="checkbox"/>
</label>
<div ng-repeat='meal in recipes' ng-show="meal.selected">
<h3>{{meal.type}}</h3>
<p>{{meal.description}}</p>
</div>
{{mean.type}
{{MEIN.type}
{{mean.description}}
或者,您可以使用复选框将数据模型项标记为选中或未选中,并基于此标记显示它们。下面是我举的一个例子:
<label ng-repeat="meal in recipes">{{meal.type}}
<input id="checkBox" ng-model="meal.selected" type="checkbox"/>
</label>
<div ng-repeat='meal in recipes' ng-show="meal.selected">
<h3>{{meal.type}}</h3>
<p>{{meal.description}}</p>
</div>
{{mean.type}
{{MEIN.type}
{{mean.description}}
我想知道按钮在哪里?你怎么了?不知道巴顿在哪里?你怎么了?不知道巴顿在哪里?你怎么了?不知道巴顿在哪里?你有什么问题?