Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我正在尝试使用angularjs获取复选框列表中的所有选定值_Javascript_Html_Angularjs_Angularjs Scope - Fatal编程技术网

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

Javascript 我正在尝试使用angularjs获取复选框列表中的所有选定值,javascript,html,angularjs,angularjs-scope,Javascript,Html,Angularjs,Angularjs Scope,**我需要在文件夹数组中获取选中的复选框值,所以我使用了ng模型。但它似乎不起作用。 **我需要“columnname:“columnvalue”格式的数组。但这将是下一步,我必须首先从复选框中获取所有选定的值 <div ng-repeat="filter in searchfilters|limitTo:4"> <div class="row form-inline advanced-search-division">

**我需要在文件夹数组中获取选中的复选框值,所以我使用了ng模型。但它似乎不起作用。 **我需要“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>

{{filter.ColumnName}
{{value}}

Sachila的答案是正确的。您要么需要将其存储在对象中,要么使用对象将其存储在该对象内的数组中。我仍然不知道为什么这是angularjs中的原因,但如果angular在声明作用域时直接将其存储在数组中,如$scope.array=[]

即使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>
另外,我会按列名将其分开,这样值就不会相互覆盖。假设您得到一个额外的列,其中的值也与“关键业务流程”的值相同,它们会覆盖这些值,并且结果不安全

因此,您应该对其进行分类,请参见此处:

angular.module(“AMYApp”,[])
.controller(“advancedSearchController”,函数($scope,$http){
$scope.searchfilters=[{
“ColumnName”:“AAAFramework”,
“ColumnValue”:“,
“TableName”:“aaaframewmaster”
},
{
“ColumnName”:“技术平台”,
“ColumnValue”:[“SAP”、“Mobile”、“Web Webforge”、“Web其他”、“Quickbase”、“SharePoint”、“其他”],
“表名”:“技术平台主控”
},
{
“ColumnName”:“CriticalBusinessProcess”,
“ColumnValue”:[“是”、“否”],
“TableName”:“CriticalBusinessProcessMaster”
},
{
“ColumnName”:“应用程序大小”,
“ColumnValue”:[“小型”、“中型”、“大型”、“大型”],
“TableName”:“ApplicationSizeMaster”
}
]
$scope.folder={};
});

{{filter.ColumnName}
{{value}}
{{文件夹}}

hey Dominik,谢谢你的时间。我尝试了你的建议,但即使这样也似乎不起作用。文件夹内容仍然为空。文件夹[filter.ColumnName][value]和文件夹[value]都未与数组绑定。不确定我缺少了什么。你是否使用了$scope.folder={};而不是$scope.folder=[]在控制器的末尾。不要使用方括号。
  $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 = {};