【问题标题】:$Scope.$Apply() returns a circular error after loading data into an Angular-Ui-Grid$Scope.$Apply() 在将数据加载到 Angular-Ui-Grid 后返回一个循环错误
【发布时间】:2016-10-28 13:19:11
【问题描述】:

一个例子: 该代码由该 HTML 触发:

<div google-chart chart = "chartObject" style = "height:600px; width:100%;" agc-on-select="selectHandler(selectedItem)" ng-if="chartvisible"></div>

这将创建一个 UI 网格:

$scope.gridOptions = gridService.getGrid([25, 50, 75], 25, ['username','startTime']);
 

    $scope.gridOptions.data = post;
     $scope.$apply();

变量“Post”类似于:

[
   {
       "challenge": "asdfrew2",
       "id": 1,
       "startTime": "start time 1",
       "successfullyCompleted": false,
       "username": "JamieFalter"
   },
   {
       "challenge": "454454y",
       "id": 2,
       "startTime": "start time 2",
       "successfullyCompleted": false,
       "username": "Falter"
   }
]

返回如下所示的错误:

TypeError:将循环结构转换为 JSON

at na (angular.js:1121)
at angular.js:20566
at Object.fn (angular.js:12411)
at k.$digest (angular.js:12540)
at k.$apply (angular.js:12805)
at Object.<anonymous> (Controller.js:54)//Points to the Scope.Apply
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at y (jquery.min.js:4)
at XMLHttpRequest.c (jquery.min.js:4)

有没有人见过这样的事情?如果有,你是怎么解决的?

【问题讨论】:

  • 为什么需要申请?该错误看起来像 JSON 指向它自己产生循环引用。
  • 我这样做是为了注意到 gridoptions8 的“数据”字段的更改。

标签: javascript angularjs json angularjs-scope angular-ui-grid


【解决方案1】:

尝试将其包装在:

$scope.$apply(function () {
 // code here
});

为了更好的错误处理。如果不行,试试 JSON 编码

【讨论】:

  • JSON 编码是什么意思?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-02
  • 1970-01-01
相关资源
最近更新 更多