我已經使用Angular ui-grid來表示來自響應的json對象數組。但是,我當前的用例在響應中返回一個字符串值數組。在這種情況下,電網應該如何配置?如何使用Angular ui-grid和字符串數組
$http.get(url)
.success(function(data) {
if(data.length <= 0 && data != undefined) {
$scope.noDataGridEpr="Data is not Available";
console.log("Data is not Available");
}
console.log("Data is" + data);
$scope.prList = data;
console.log("prList is" + $scope.prList); //an array of strings
$scope.dataLoadedEpr=true;
return true;
})
.error(function(data, status) {
console.log("Error from controller. Could not query.");
return false;
})
這將打印
prList is[A/DN,B/LCK,10,10,same,match,match],
[B/DN,D/LCK,10,10,same,mismatch,match],
[G/DN,D/LCK,10,10,same,mismatch,mismatch]
這是我目前的格狀構造的外觀
$scope.prGrid = {
data: 'prList',
columnDefs: [
{field: 'DPin', displayName: 'DPin', width: "5%"},
{field: 'CPin', displayName: 'CPin', width: "5%"},
{field: 'slack1', displayName: 'slack1', width: "5%"},
{field: 'slack2', displayName: 'slack2', width: "5%"},
{field: 'cComp', displayName: 'cComp', width: "10%"},
{field: 'dComp', displayName: 'dComp', width: "5%"},
{field: 'gComp', displayName: 'dComp', width: "5%"}
enableFiltering: true,
multiSelect: false,
enableGridMenu: true,
enableRowHeaderSelection: false,
enableSorting: true,
enableColumnResizing: true
};
我明白上述領域的配置不正確。鑑於我有一個字符串數組作爲我/ P,有人可以指導我如何設置網格中的字符串數組,每個代表一行?
謝謝。
如何關於每個字符串數組映射到一個對象?對象的每個屬性都將按照上面所述的字段命名 – AranS