[英]I am trying to get all selected values in the list of checkbox using angularjs
**i need to get selected checkbox values in folder array so i have used ng-model. **我需要在文件夹数组中获取选定的复选框值,所以我使用了ng-model。 but it seems to be not working.
但它似乎不起作用。 **i need the array in "columnname:"columnvalue" format. but that would be the next step, i have to get all selected values from checkboxes first
**我需要“ columnname:“ columnvalue”格式的数组。但这将是下一步,我必须首先从复选框中获取所有选定的值
<div ng-repeat="filter in searchfilters|limitTo:4">
<div class="row form-inline advanced-search-division">
<span class="col-md-3 col-xl-3 col-lg-3 col-sm-12">
<label for="PriorityCheckbox" class="task-content-text"> {{filter.ColumnName}}</label>
</span>
<span class="col-md-9 col-xl-9 col-lg-9 col-sm-12">
<span ng-repeat="value in filter.ColumnValue" >
<span ng-if="value !== ' '" class="checkbox-inline">
<label class="task-content-text" style="margin-right:50px"><input type="checkbox" ng-model="folder[value]" /> {{value}}</label>
</span>
<span ng-if="value == ' ' ">
<input type="text" />
</span>
</span>
</span>
</div>
</div>
angular.module("AMYApp").controller("advancedSearchController", function ($scope, $http) { $scope.searchfilters = [{ "ColumnName": "AAAFramework", "ColumnValue":" ", "TableName": "AAAFrameworkMaster" }, { "ColumnName": "TechnologyPlatform", "ColumnValue": ["SAP","Mobile","Web-Webforge","Web-Other","Quickbase","SharePoint","Other"], "TableName": "TechnologyPlatformMaster" }, { "ColumnName": "CriticalBusinessProcess", "ColumnValue": ["Yes","No"], "TableName": "CriticalBusinessProcessMaster" }, { "ColumnName": "ApplicationSize", "ColumnValue": ["Small", "Medium", "Large", "MEGA"], "TableName": "ApplicationSizeMaster" } ] $scope.folder = []; }
<div ng-repeat="filter in searchfilters|limitTo:4"> <div class="row form-inline advanced-search-division"> <span class="col-md-3 col-xl-3 col-lg-3 col-sm-12"> <label for="PriorityCheckbox" class="task-content-text">{{filter.ColumnName}}</label> </span> <span class="col-md-9 col-xl-9 col-lg-9 col-sm-12"> <span ng-repeat="value in filter.ColumnValue" > <span ng-if="value !== ' '" class="checkbox-inline"> <label class="task-content-text" style="margin-right:50px"><input type="checkbox" ng-model="folder[value]" /> {{value}}</label> </span> <span ng-if="value == ' ' "> <input type="text" /> </span> </span> </span> </div> </div>
Sachila's answer is right. Sachila的答案是正确的。 you either need to store it in an object or use an object to store it in an array inside this object.
您要么需要将其存储在一个对象中,要么使用一个对象将其存储在该对象内部的数组中。 I still don't know why this is the reason in angularjs, but you will often have this problem in angular trying to directly storing in an array when its declared to scope like this $scope.array = [];
我仍然不知道为什么这是angularjs的原因,但是当声明为$ scope.array = [];这样的作用域时,在尝试直接存储在数组中时经常会遇到角度问题。
Even when Sachila was faster, here me solution: 即使Sachila更快,这里也提供解决方案:
<div ng-repeat="filter in searchfilters|limitTo:4">
<div class="row form-inline advanced-search-division">
<span class="col-md-3 col-xl-3 col-lg-3 col-sm-12">
<label for="PriorityCheckbox" class="task-content-text">{{filter.ColumnName}}</label>
</span>
<span class="col-md-9 col-xl-9 col-lg-9 col-sm-12">
<span ng-repeat="value in filter.ColumnValue" >
<span ng-if="value != ''" class="checkbox-inline">
<label class="task-content-text" style="margin-right:50px"><input type="checkbox" ng-model="folder.values[value]" /> {{value}}</label>
</span>
<span ng-if="value == ' ' ">
<input type="text" />
</span>
</span>
</span>
</div>
</div>
and inside the controller: 在控制器内部:
$scope.searchfilters = [{ "ColumnName": "AAAFramework", "ColumnValue":" ", "TableName": "AAAFrameworkMaster" },
{ "ColumnName": "TechnologyPlatform", "ColumnValue": ["SAP","Mobile","Web-Webforge","Web-Other","Quickbase","SharePoint","Other"], "TableName": "TechnologyPlatformMaster" },
{ "ColumnName": "CriticalBusinessProcess", "ColumnValue": ["Yes","No"], "TableName": "CriticalBusinessProcessMaster" },
{ "ColumnName": "ApplicationSize", "ColumnValue": ["Small", "Medium", "Large", "MEGA"], "TableName": "ApplicationSizeMaster" }
]
$scope.folder = {};
also i would seperate it by column name, so the values dont overwrite each other. 我也将按列名将其分开,因此值不会互相覆盖。 Imagine you get an additional column where values are also Yes and No like for "Critical Business Process" They would overwrite these values and the results are not secure.
想象一下,您会获得一个附加列,其中的值也是“关键业务流程”的“是”和“否”,它们将覆盖这些值并且结果是不安全的。
So you should categorize it, see here: 因此,您应该对其进行分类,请参见此处:
angular.module("AMYApp",[]) .controller("advancedSearchController", function($scope, $http) { $scope.searchfilters = [{ "ColumnName": "AAAFramework", "ColumnValue": " ", "TableName": "AAAFrameworkMaster" }, { "ColumnName": "TechnologyPlatform", "ColumnValue": ["SAP", "Mobile", "Web-Webforge", "Web-Other", "Quickbase", "SharePoint", "Other"], "TableName": "TechnologyPlatformMaster" }, { "ColumnName": "CriticalBusinessProcess", "ColumnValue": ["Yes", "No"], "TableName": "CriticalBusinessProcessMaster" }, { "ColumnName": "ApplicationSize", "ColumnValue": ["Small", "Medium", "Large", "MEGA"], "TableName": "ApplicationSizeMaster" } ] $scope.folder = {}; });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="AMYApp" ng-controller="advancedSearchController"> <div ng-repeat="filter in searchfilters|limitTo:4"> <div class="row form-inline advanced-search-division"> <span class="col-md-3 col-xl-3 col-lg-3 col-sm-12"> <label for="PriorityCheckbox" class="task-content-text">{{filter.ColumnName}}</label> </span> <span class="col-md-9 col-xl-9 col-lg-9 col-sm-12"> <span ng-repeat="value in filter.ColumnValue" > <span ng-if="value !== ' '" class="checkbox-inline"> <label class="task-content-text" style="margin-right:50px"><input type="checkbox" ng-model="folder[filter.ColumnName][value]" /> {{value}}</label> </span> <span ng-if="value == ' ' "> <input type="text" /> </span> </span> </span> </div> </div> {{folder}} </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.