Ionic(Angularjs)和Devextreme Datagrid的集成未能显示来自$http JSON的数据
我正在使用Angularjs开发一个离子应用程序。在我的应用程序中,我必须与诸如Datagrid之类的devextreme组件集成 当我尝试将JSON放在本地并显示在devextreme datagrid中时,它显示得非常完美。然而,当我通过使用$http从web服务获取JSON数据并在devextreme Datagrid中显示时。它无法显示它,但当我控制台输出数据时,我能够获取数据,只是无法在Devextreme Datagrid组件中显示它 下面是我的示例代码 html代码Ionic(Angularjs)和Devextreme Datagrid的集成未能显示来自$http JSON的数据,angularjs,devextreme,angularjs-http,ionic-v1,dx-data-grid,Angularjs,Devextreme,Angularjs Http,Ionic V1,Dx Data Grid,我正在使用Angularjs开发一个离子应用程序。在我的应用程序中,我必须与诸如Datagrid之类的devextreme组件集成 当我尝试将JSON放在本地并显示在devextreme datagrid中时,它显示得非常完美。然而,当我通过使用$http从web服务获取JSON数据并在devextreme Datagrid中显示时。它无法显示它,但当我控制台输出数据时,我能够获取数据,只是无法在Devextreme Datagrid组件中显示它 下面是我的示例代码 html代码 <ion
<ion-view view-title="Dashboard">
<ion-content class="padding">
<div dx-data-grid="{
dataSource: customers,
keyExpr: 'ID',
columns: ['toponymName', 'fcodeName', 'population'],
sorting: { mode: 'single' },
pager: { visible: true },
paging: { pageSize: 10 },
editing: {
editEnabled: false,
editMode: 'row',
insertEnabled: false,
removeEnabled: false
},
allowColumnReordering: true,
allowColumnResizing: true,
filterRow: { visible: true },
searchPanel: { visible: false },
selection: { mode: 'single' }
}"></div>
</ion-content>
</ion-view>
就像我试过的注释代码,JSON文件的硬代码。它能够成功地显示。如果我从$http获取,它将无法在dx数据网格中显示数据 这是一个时间问题。在将数据异步加载到网格中之后,必须调用
refresh
方法
小部件无法跟踪第三方在数据源中所做的更改。在这种情况下,要使小部件中的数据更新,请调用此方法。查找列的数据源将与主数据源一起更新
资料来源:
Soll您所需要做的就是按照所描述的步骤进行操作,然后在小部件上调用refresh
方法
.controller('DashCtrl', function($scope, $http) {
$http({
method : 'GET',
url : 'http://10.194.121.224/MobileGo_WebAPI/api/MST_CUSTOMER',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(function successCallback(response) {
$scope.customers = response.data;
console.log(response.data)
}, function errorCallback(response) {
console.log(response.statusText);
});
// var customers = [{
// ID: 1,
// CompanyName: "Super Mart of the West",
// CompanyHolder: "Chan Yoong Hon",
// City: "Bentonville",
// State: "Arkansas"
// }, {
// ID: 2,
// CompanyName: "Electronics Depot",
// CompanyHolder: "Lee Kam Fei",
// City: "Atlanta",
// State: "Georgia"
// }];
// $scope.customers = customers;
})