Eri*_*eis 2 arrays angularjs angularjs-scope angularjs-ng-repeat
当我使用concat方法时,我的$ scope不会更新
var anotherList = ["2", "3", "4"];
$scope.list = [];
$scope.list.concat(anotherList);
Run Code Online (Sandbox Code Playgroud)
但是在循环中使用数组推送方法,我的$ scope会更新
你的语法错了.您需要将返回值分配给.concat()范围数组.
$scope.list = $scope.list.concat(anotherList);
Run Code Online (Sandbox Code Playgroud)
或者,如果您使用过,call()您可以将结果直接绑定到作用域数组,而无需"重新分配",因为它将在您的引擎盖下完成.
$scope.list.concat.call(anotherList);
Run Code Online (Sandbox Code Playgroud)
请参阅文档.
| 归档时间: |
|
| 查看次数: |
489 次 |
| 最近记录: |