gpt4 book ai didi

javascript - 在AngularJS中,模型更新后如何更新 View ?

转载 作者:行者123 更新时间:2023-12-03 12:35:27 24 4
gpt4 key购买 nike

在下面的代码片段中,两个变量 $scope.recordList$scope.recordList2 具有完全相同的值。 $scope.recordList2 已设置静态值,$scope.recordList 在收到服务器响应后更新。语句 $scope.recordList$scope.recordList2 呈现相同的值,$scope.recordList 在收到响应后呈现。

最后有两个智能表( https://github.com/lorenzofox3/Smart-Table )。 $scope.recordList2 基表按预期工作。基于 $scope.recordList 的表无法按预期工作。

在AngularJS中,模型更新后如何更新 View ?

<div ng-app="smartTableApp" ng-controller="smartTableController">
<script>
angular.module('smartTableApp', [ 'AngularJSRemoting','smartTableApp.controllers', 'smartTable.table']);
angular.module('smartTableApp.controllers', []).controller('smartTableController', function($scope, jsr) {

jsr.Call('appController.query', '{!soql}').then(function(response) {
$scope.recordList = response;
//$scope.$apply() ; uncommenting this gives "$digest already in progress" error
},function(err){
console.log(err);
});

$scope.recordList2=[{"attributes":{"type":"Contact","url":"/services/data/v30.0/sobjects/Contact/0039000000wvt6yAAA"},"Name":"Stella Pavlova","Phone":"(212) 842-5500","CreatedDate":"2014-05-15T06:17:48.000+0000","Id":"0039000000wvt6yAAA"},{"attributes":{"type":"Contact","url":"/services/data/v30.0/sobjects/Contact/0039000000wvt6zAAA"},"Name":"Lauren Boyle","Phone":"(212) 842-5500","CreatedDate":"2014-05-15T06:17:48.000+0000","Id":"0039000000wvt6zAAA"},{"attributes":{"type":"Contact","url":"/services/data/v30.0/sobjects/Contact/0039000000wvt70AAA"},"Name":"Babara Levy","Phone":"(503) 421-7800","CreatedDate":"2014-05-15T06:17:48.000+0000","Id":"0039000000wvt70AAA"},{"attributes":{"type":"Contact","url":"/services/data/v30.0/sobjects/Contact/0039000000wvt71AAA"},"Name":"Josh Davis","Phone":"(503) 421-7800","CreatedDate":"2014-05-15T06:17:48.000+0000","Id":"0039000000wvt71AAA"},{"attributes":{"type":"Contact","url":"/services/data/v30.0/sobjects/Contact/0039000000wvt72AAA"},"Name":"Jane Grey","Phone":"(520) 773-9050","CreatedDate":"2014-05-15T06:17:48.000+0000","Id":"0039000000wvt72AAA"}] ;

});
</script>
<br/>----------recordList----------<br/><!-- Shows expected values -->
{{recordList}}
<br/>----------recordList2----------<br/><!-- Shows expected values -->
{{recordList2}}
<br/><br/>
<smart-table rows="recordList" ></smart-table><br/><br/><!-- table is NOT rendered -->
<smart-table rows="recordList2" ></smart-table><br/><br/><!-- table is rendered -->
</div>

最佳答案

问题不在于 Angular 没有更新 View 。事实上,您在代码示例中指出它正在更新它:

<br/>----------recordList----------<br/><!-- Shows expected values -->
{{recordList}}

我没有使用 Smart-Table 的经验,但我确实找到了 this issue GitHub 上有报道,它描述了与您类似的问题。该模块的作者确实回复了,并建议仅使用列配置来初始化表,以避免出现此问题(他将其描述为错误)。

因此,如果您在查询之前了解数据的结构,则应该使用列数据初始化表。

关于javascript - 在AngularJS中,模型更新后如何更新 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23753668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com