$scope.itemarray = ['A', 'B', 'C'];
这将清除数组,但不会更新 ui。
$scope.itemarray = [];
这很好用!为什么?
$scope.itemarray.length = 0;
最佳答案
$scope.itemarray.length = 0;
<< 这是正确的。长度为读写属性。
$scope.itemarray = [];
<< 这会创建一个新的空数组。如果您绑定(bind)到旧的 itemarray,它们可能会丢失。 (像 ng-if="itemarray[0]"
这样的 Html 绑定(bind)不会丢失)
关于javascript - 如何清除 angularJS 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29803045/