Angular js UI 网格未更新新内容 [英] Angular js UI grid is not getting updated with new content
问题描述
我正在调用 $http.get 以从服务器获取用于 angular ui 网格的新内容.在日期选择器中更改日期时,我触发 ng-change 事件以进行另一个 http 调用以获取新内容.调用成功,但网格未更新新内容.$scope.grid.core.notifyDataChange() 在 http 成功回调中调用时抛出错误.请建议使用新内容更新网格的方法.
I am calling $http.get to get new content from the server for angular ui grid. On change of date in the datepicker I trigger an ng-change event to make another http call to get new content. The call is successful but the grid is not updated with new content.$scope.grid.core.notifyDataChange() throws error when called inside the http success call back.Please suggest ways to update the grid with new content.
请找到 plnkr 代码.当我单击加载按钮时,我想使用 http 调用用新的 JSON 数据更新网格,但它没有更新网格.http://plnkr.co/edit/S2A3scEoO6QIGFbru3Lr?p=preview代码>
Please find the plnkr code. when I click load button, I want to update grid with new JSON data using http call but it is not updating grid. http://plnkr.co/edit/S2A3scEoO6QIGFbru3Lr?p=preview
推荐答案
你的例子的问题在于 $http
的 success
方法(第 256-260 行).
The problem with your example is inside $http
's success
method(lines 256-260).
$http.get(...).success(
function(data){
$scope.roData = data;
});
您只是将数据放入范围属性 ($scope.roData
) 中,但您并未对该范围属性执行任何操作.
There you are just putting your data inside a scope property ($scope.roData
), but then you're not doing anything with that scope property.
此外,您尝试使用以下行为 uiGrid.gridOptions.data
分配错误的值:
Furthermore you're trying to assign a wrong value to uiGrid.gridOptions.data
with the lines:
if($scope.gridOptions.data ==='rData'){
$scope.gridOptions.data = 'roData';
}
但是你犯了两个错误:
把变量当作字符串来处理,这是行不通的.在您的 JS 文件中,您需要使用
$scope.nameOfVariable
访问您的范围,而不是使用它们的名称作为字符串,例如'nameOfVariable'
.
Treating variables as string, and this is not going to work. Inside your JS files you need to access your scope with
$scope.nameOfVariable
not by using their names as strings like'nameOfVariable'
.
您将这些行放在 success
方法之外,因此它们会在您实际获取数据之前执行.
You put these lines outside of your success
method, so they are executed before you actually get your data.
我设法编辑了您的 plunker 并使其正常工作,您可以在此处找到它.我所做的是将您的线条放在一起并修复名称错误.我没有把任何if
放在那里,因为我不知道你想完成什么逻辑.
I managed to edit your plunker and make it work, you can find it here.
What I did was putting your lines together and fix the name error. I did not put there any if
since I don't know what logic you wanted to accomplish.
$http.get(...).success(
function(data){
$scope.roData = data;
$scope.gridOptions.data = $scope.roData;
});
这篇关于Angular js UI 网格未更新新内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!