Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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访问ng重复复选框_Javascript_Angularjs - Fatal编程技术网

Javascript angularjs访问ng重复复选框

Javascript angularjs访问ng重复复选框,javascript,angularjs,Javascript,Angularjs,我正在执行ng repeat以从数组中输出复选框 <div class="row-fluid"> <label ng-repeat="checkbox_ in checkboxes" class="checkbox" for="checkbox_{{$index}}"> <input name="checkbox_{{$index}}" id="checkbox_{{$index}}"

我正在执行ng repeat以从数组中输出复选框

<div class="row-fluid">
    <label ng-repeat="checkbox_ in checkboxes" class="checkbox"
        for="checkbox_{{$index}}">
            <input name="checkbox_{{$index}}" id="checkbox_{{$index}}"
                ng-model="checkbox_.checked"
                ng-true-value="{checkbox_.value}"
                type="checkbox">
            {{checkbox_.text}}
    </label>
</div>
<pre>{{checkboxes | json}}</pre>
之后,我想访问复选框_1,例如

<hr>
checkbox_1.checked - {{checkbox_1.checked}}<br>
checkbox_1.value - {{checkbox_1.value}}<br>
checkboxes[1].checked - {{checkboxes[1].checked}}<br>
checkboxes[1].value - {{checkboxess[1].value}}<br>checkbox_1.value - {{checkbox_1.value}}<br>

<div ng-show="checkboxes[1].checked">on</div>

复选框_1.checked-{{checkbox_1.checked}}
复选框_1.value-{{checkbox_1.value}}
复选框[1]。选中-{{复选框[1]。选中}}
复选框[1]。值-{{checkboxess[1]。值}}
checkbox\u 1.value-{{checkbox\u 1.value}}
在…上
什么也没发生


当用户将checkbox1值“text2”设置为true时,如何访问该值?ty

您的代码很好-除了JS中的数组是从0而不是1索引的。因此,您应该有复选框[0]。改为选中

顺便说一句-为了调试,我建议使用

{{复选框| json}

你想要这样的东西吗

you selected <span ng-repeat="checkbox_ in checkboxes" ng-show="checkbox_.checked"> {{checkbox_.text}}</span> 
您选择了{{复选框[0].text}
{{复选框[1]。文本}

或者使用ng repeat动态执行此操作:

您选择了{{checkbox..text}


用于分离关注点和正确使用MVC结构(如angularjs)的方法。不应直接访问DOM复选框以获取其选中状态和文本,而应访问模型。

但我想访问复选框1而不是复选框[1]?它的ng_true_值在哪里?例如,我想这样做您选择了{{复选框[1]。值+''+复选框[2]。值}

并且用户应该看到“您选择了文本2 text4”
you selected <span ng-show="checkboxes[0].checked"> {{checkboxes[0].text}}</span> 
<span ng-show="checkboxes[1].checked"> {{checkboxes[1].text}}</span>
you selected <span ng-repeat="checkbox_ in checkboxes" ng-show="checkbox_.checked"> {{checkbox_.text}}</span>