gpt4 book ai didi

javascript - 在 Angular UI 网格中显示数据

转载 作者:行者123 更新时间:2023-11-27 23:21:00 25 4
gpt4 key购买 nike

我在 ui 网格表中显示数据时遇到问题。

我已经定义了一个 API,我想从中显示数据,并且可以通过浏览器访问它们,但问题在于显示渲染的数据。这是我的 Angular Controller ,我在其中定义了用于从 API 获取数据的函数:

        getData();

$scope.myData = [];

$scope.gridOptions.data = []

$scope.gridOptions.data = $scope.myData;

function getData() {
$http.get('/load/').success(function (data) {
data.forEach( function( row, index ) {
$scope.myData.push(data);
});
$scope.gridOptions.data = data;
console.log('data from api', data);
})
};

我得到了空网格。 enter image description here

数据显示在控制台中: enter image description here

我也尝试过解析数据 var jsonObj = JSON.parse(data);,但出现错误 意外 token o 在 Object.parse( native )

最佳答案

使用此函数将数据推送到数组中。在控制台中检查您的数据,深入了解您的数据。 (单击箭头)我的数据位于 .doc 中,您的数据可能位于另一个属性中。将“items[i].doc”更改为数据的正确属性。

// pass data.rows to function items params
// the type is to filter
function fncArray(items,type) {
var filtered = [];
for(var i=0; i < items.length; i++) {
if ( items[i].doc.type = type){
filtered.push(items[i].doc);
}
}
// console.log(filtered);
return filtered;
}

这是不过滤使用

// pass data.rows to function items params 
function fncArray(items) {
var newData= [];
for(var i=0; i < items.length; i++) {
newData.push(items[i].doc);
}
return newData;
}

关于javascript - 在 Angular UI 网格中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35360986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com