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()时会引发错误.请建议使用新内容更新网格的方法.
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属性($scope.roData
)中,但是随后您没有使用该scope属性做任何事情.
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';
}
但是您犯了2个错误:
-
将变量作为字符串处理,这将无法正常工作.在您的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.
我设法编辑了您的监听器并使之工作,您可以在此处 .
我所做的就是将您的台词整理在一起,并修复名称错误.因为我不知道您要完成什么逻辑,所以我没有在其中放置任何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屋!