[英]How to pass check box values in AngularJS using ng-model in conjunction with ng-repeat
我有一个页面,该页面使用户能够通过输入搜索词来搜索文章并根据需要过滤结果。
过滤器最初包含多个选择框,其中的值是从ajax调用中获取的,并且使用ng-model将选定的值发送回去。 工作正常。
现在,要求将多个选择框转换为复选框,而我已经设法创建了该复选框。
当用户输入搜索查询并选中其中一个复选框时,我遇到了问题,我无法在app.js中获取选定的复选框值来过滤结果。
<div class="col-lg-3">
<h3 class="m0 pb-lg">Filters</h3>
<div class="form-group mb-xl">
<form method="get" ng-controller="SearchController as form" class="form-horizontal">
<label class="control-label mb">By Type of Study</label><br><label class="checkbox-inline c-checkbox" ng-repeat="s in form.typeOfStudies">
<input type="checkbox" ng-model="search.typeOfStudy" ng-true-value="'YES'" ng-false-value="'NO'">
<span class="fa fa-check"></span>{{s}}</input>
</label>
<br>
</form>
</div>
</div>
</div>
app.js包含:
$scope.getById = function (id) {
if (id.typeOfStudy){
$.each(id.typeOfStudy, function() {
if (count < id.typeOfStudy.length) {
count++;
qTypeOfStudy += "'" + this + "',";
}
else if (count == id.typeOfStudy.length) {
qTypeOfStudy += "'" + this + "'";
}
})
}
}
在页面上的搜索栏中提交主体文本的表单时,会传递getById。
我正在使用ng-repeat
列表中的某些值作为id,您可以s in form.typeOfStudies
中包含s in form.typeOfStudies
。 像这样的东西:
<div ng-repeat="modelList in modelsLists">
<input type="checkbox" ng-model="selection.ids[modelList.id]" id="{{modelList.id}}"/>
</div>
在JS中初始化:
$scope.selection = {
ids: {}
};
并检查复选框:
if($scope.selection.ids[id]){
// do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.