我正在用angularjs开发一个离子应用程序。在我的应用程序中,我必须与像datagrid这样的devextreme组件集成。
当我尝试将json放在本地并显示在devextreme datagrid中时,它显示得非常完美。但是,当我使用$http从web服务获取json数据并显示在devextreme datagrid中时。它无法显示它,但当我控制台出数据时,我能够获得数据,只是无法在devextreme datagrid组件中显示它。
下面是我的示例代码
HTML代码
<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>
控制器代码
.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;
})
就像我试过的注释代码,json文件的硬代码。它能够成功显示。如果我从$http获取,它将无法在dx数据网格中显示数据。