做一個循環迴路內的一個觀點:
<tr ng-repeat="result in results">
<td>
<span ng-repeat="device in helpers.getIosDevices(result.ios_device)">
{{ device.code }}
</span>
</td>
</tr>
控制器:
$scope.helpers = CRM.helpers;
助手:
var CRM = CRM || {};
CRM.helpers = {
// Handle "111" value format
getIosDevices: function (devices) {
var obj = [];
if (devices !== null && devices !== undefined) {
if (devices.charAt(0) === '1') {
obj.push({
code: 'ipod',
name: 'iPod',
});
}
if (devices.charAt(1) === '1') {
obj.push({
code: 'ipad',
name: 'iPad',
});
}
if (devices.charAt(2) === '1') {
obj.push({
code: 'iphone',
name: 'iPhone',
});
}
}
return obj;
}
};
得到這個錯誤:https://docs.angularjs.org/error/ $ rootScope/infdig?p0 = 10 & p1 =%5B%5B%22fn:%E2%80%A620%20%20%7D;%20newVal:%20undefined;%20oldVal:%20undefine d%22%5D%5D
據我所知,但我不知道如何解決它在我的情況。我應該使用哪種解決方法?
那麼如何重寫這個以避免異常呢?在大多數情況下,創建的數組總是相同的。 – Syl 2014-11-03 09:20:13
@sylouuu增加了一些演示 – 2014-11-03 09:38:27
謝謝你的作品! – Syl 2014-11-03 09:56:17