我的问题应该很简单。
如果在vm.application.obligations
对象中我没有holderId == 2,我只想插入一个空行
但我的代码是为每个vm.application.obligations
插入一个空行。
如何只插入一个空行?
<tr class="text-center" ng-if="obligation.debtor.holderId != 2"
ng-repeat="obligation in vm.application.obligations track by $index">
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
将逻辑转换为javascript并让html显示数据而不需要条件是个好主意。例如。 JS:
vm.uiData = [];
obligations.forEach(function (obligation) {
if (obligation.debtor.holderId === 2) {
vm.uiData.push("");
} else {
// push to uiData what should be displayed in the normal behavior..
}
});
HTML:
<tr class="text-center" ng-repeat="text in vm.uiData track by $index">
<td>{{text}}</td>
</tr>
如果在
vm.application.obligations
对象中我没有holderId == 2
,我只想插入一个空行
<tr class="text-center" ng-if="vm.noHolderIdEq2()"
̶n̶g̶-̶r̶e̶p̶e̶a̶t̶=̶"̶o̶b̶l̶i̶g̶a̶t̶i̶o̶n̶ ̶i̶n̶ ̶v̶m̶.̶a̶p̶p̶l̶i̶c̶a̶t̶i̶o̶n̶.̶o̶b̶l̶i̶g̶a̶t̶i̶o̶n̶s̶ ̶t̶r̶a̶c̶k̶ ̶b̶y̶ ̶$̶i̶n̶d̶e̶x̶"̶ >
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
vm.noHolderIdEq2 = function() {
var arr = vm.application.obligations.filter(x => x.holderId == 2);
return arr.length == 0;
};