【发布时间】:2016-01-26 11:38:37
【问题描述】:
我像往常一样做一个简单的 ng-repeat,但这次失败了,我不知道发生了什么......
这是我的 HTML 部分:
<p ng-repeat="mow in check.BankDataParent.mows">
<div class="checkbox">
<input type="checkbox" ng-model="mow.selected" />
<label for="checkbox"></label>
</div>
<i class="fa fa-exclamation-triangle"
style="color:red;"
title="{{mow.errorInputAmountTitle}}"
ng-show="mow.selected && mow.errorInputAmountTitle"></i>
<input type="text" ng-model="mow.inputAmount" size="8" ng-show="mow.selected" />
{{mow.displayField}}
<a href="/{{mow.id}}" target="_blank"><i class="fa fa-external-link"></i></a>
</p>
这就是它的渲染方式(当我通过浏览器执行检查元素时):
<!-- ngRepeat: mow in check.BankDataParent.mows -->
<p ng-repeat="mow in check.BankDataParent.mows" class="ng-scope">
</p>
<!-- end ngRepeat: mow in check.BankDataParent.mows -->
<p ng-repeat="mow in check.BankDataParent.mows" class="ng-scope">
</p>
<!-- end ngRepeat: mow in check.BankDataParent.mows -->
<p ng-repeat="mow in check.BankDataParent.mows" class="ng-scope">
</p><!-- end ngRepeat: mow in check.BankDataParent.mows -->
<div class="checkbox">
<input type="checkbox" ng-model="mow.selected" class="ng-pristine ng-untouched ng-valid">
<label for="checkbox"></label>
</div>
<i class="fa fa-exclamation-triangle ng-hide" style="color:red;" title="" ng-show="mow.selected && mow.errorInputAmountTitle"></i>
<input type="text" ng-model="mow.inputAmount" size="8" ng-show="mow.selected" class="ng-pristine ng-untouched ng-valid ng-hide">
<a href="/" target="_blank"><i class="fa fa-external-link"></i></a>
<p></p>
PS:这就是在 check.BankDataParent.mows 中有 4 个元素时的解析方式......所有的
是空白,最后只有一个内容,但它也是空的(没有数据)...
你知道发生了什么吗?
更新 感兴趣的事情:我将代码更改为:
<p ng-repeat="mow in check.BankDataParent.mows">
<!-- <input type="checkbox" ng-model="mow.selected" /> -->
<div class="checkbox">
<input type="checkbox" ng-model="mow.selected" name="cbmow{{mow.id}}" />
<label for="cbmow{{mow.id}}"></label>
</div>
以上部分的其余部分保持不变...... 现在的输出是:
<!-- ngRepeat: mow in check.BankDataParent.mows -->
<p ng-repeat="mow in check.BankDataParent.mows" class="ng-scope">
<!-- <input type="checkbox" ng-model="mow.selected" /> -->
</p>
<!-- end ngRepeat: mow in check.BankDataParent.mows -->
<p ng-repeat="mow in check.BankDataParent.mows" class="ng-scope">
<!-- <input type="checkbox" ng-model="mow.selected" /> -->
</p>
<!-- end ngRepeat: mow in check.BankDataParent.mows -->
<p ng-repeat="mow in check.BankDataParent.mows" class="ng-scope">
<!-- <input type="checkbox" ng-model="mow.selected" /> -->
</p>
<!-- end ngRepeat: mow in check.BankDataParent.mows -->
<p ng-repeat="mow in check.BankDataParent.mows" class="ng-scope">
<!-- <input type="checkbox" ng-model="mow.selected" /> -->
</p>
<!-- end ngRepeat: mow in check.BankDataParent.mows -->
<div class="checkbox">
<input type="checkbox" ng-model="mow.selected" name="cbmow" class="ng-valid ng-dirty ng-valid-parse ng-touched">
<label for="cbmow"></label>
</div>
<i class="fa fa-exclamation-triangle ng-hide" style="color:red;" title="" ng-show="mow.selected && mow.errorInputAmountTitle"></i>
<input type="text" ng-model="mow.inputAmount" size="8" ng-show="mow.selected" class="ng-pristine ng-untouched ng-valid ng-hide">
<a href="/" target="_blank"><i class="fa fa-external-link"></i></a>
<p></p>
现在我想知道这是否是与复选框图像的 CSS 冲突?
这是我的 CSS:
.checkbox {
display: inline-block;
width: 24px;
height: 24px;
position: relative;
cursor: pointer;
margin: 0px 10px -5px 0;
}
.checkbox input[type="checkbox"] {
opacity: 0;
width: 24px;
height: 24px;
position: absolute;
top: 0;
left: 0;
z-index: 1070;
cursor: pointer;
}
.checkbox label {
display: block;
width: 24px;
height: 24px;
position: relative;
border: 1px solid #eee;
border-radius: 3px;
}
.checkbox input[type="checkbox"]:checked + label {
background-image: url("../images/icons.png");
}
【问题讨论】:
-
看起来你一定是在
<div class="checkbox">之前不小心关闭了<p>标签,但我看不出你发布的内容有什么问题——你确定它不是写成@987654328吗@(“/”结尾)? -
在
ng-repeat之前尝试{{check.BankDataParent.mows}}并检查显示的内容。 -
感谢@Rhumborl 的快速回复,您能检查一下更新吗?我认为这与CSS有冲突,可能吗?
-
感谢@Raghu 的快速回复,您能检查一下更新吗?我认为这与CSS有冲突,可能吗?
-
@LeoRibeiro 不是 css 的问题。我已经更新了答案。请检查一下。
标签: javascript angularjs