简体   繁体   English

我正在尝试使用angularjs获取复选框列表中的所有选定值

[英]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.

相关问题 如何使用angularjs在复选框列表中推送选定的值 - How to push selected values in checkbox list using angularjs 如何使用angularjs获取选中的复选框值和选定的下拉值? - how to get checked checkbox values and selected dropdown value using angularjs? 从angularjs中的树中获取选定的复选框值 - get selected checkbox values from tree in angularjs 列表中选中的AngularJS复选框 - AngularJS checkbox selected in a list 我正在尝试使用jquery从下拉列表中获取选定的值。 由于某些原因,所选选项未打印到控制台。 Helppss - I am trying to get the selected value from a dropdown list using jquery. For some reason, the option selected is not printing to the console. Helppss 如何在angularjs中的按钮单击事件上获取选定的复选框值 - How to get selected checkbox values on a button click event in angularjs 嗨,我试图仅根据所选值Angularjs在选项卡上 - Hi I am trying to only on tab according to the selected value Angularjs 我正在尝试使用AngularJS发布数据 - I am Trying to Post Data Using AngularJS 在多选下拉列表中,我无法获取列表中空格后的所选值 - In multi select drop down I am not able to get the selected values after the spaces in the list AngularJs将在所有其他复选框上切换选中的复选框 - AngularJs Checkbox that will toggle selected on all other checkboxes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM