2017-03-02 130 views
0

ag-Grid,跟随在JavaScript的official demo之后,但使用真实世界的API来处理硬编码数据。注意:不需要jQuery,只需使用原始的纯XMLHttpRequest()作为ajax。ag-Grid javaScript,TypeError:rowData未定义

  • F12在相同的结构验证API返回的数据作为演示,内部有孩子节点,gripOptions.rowData分配与返回的数据。
  • 试了实例rowData内的gripOptions作为 rowData: [], 得到了同样的错误,或者 rowData: {},得到的ReferenceError:未定义rowData。

HTML:

<script src="/scripts/agGrid/ag-grid.js"></script> 
<script src="/scripts/agGrid/myAG.js"></script> 
<br />JavaScript ag-Grid 
<div id="myGrid" style="height: 200px;" class="ag-fresh"></div> 

myAG.js:

var httpApi = new XMLHttpRequest(); 
var columnDefs = [ 
    { headerName: "Client Name", field: "ClientName", unSortIcon: true, cellRenderer: "group" }, 
    { headerName: "Division", field: "Division" }, 
    { headerName: "Others", field: "Others" } 
]; 
var gridOptions = { 
    columnDefs: columnDefs, 
    getNodeChildDetails: getNodeChildDetails 
}; 

function getNodeChildDetails(rowItem) { 
    if (rowItem.ClientName) { 
     return { 
      group: true, 

     // provide ag-Grid with the children of this group 
      children: rowItem.children, 

      // the key is used by the default group cellRenderer 
      key: rowItem.ClientName 
     }; 
    } else { 
     return null; 
    } 
} 

// wait for the document to be loaded, otherwise 
// ag-Grid will not find the div in the document. 
document.addEventListener("DOMContentLoaded", function() { 
    $.ajax({ 
     type: "GET", 
     url: "/api/myAG/Tree", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (data) { 
      gridOptions.rowData = data; 
      var eGridDiv = document.querySelector('#myGrid'); 
      new agGrid.Grid(eGridDiv, gridOptions); 
     }, 
     error: function (XMLHttpRequest, textStatus, errorThrown) { 
      alert(errorThrown); 
     } 
    }) 

}); 

版本: AG-网格= V8.1.0 火狐= 50.1.0

错误消息: Error msg

F12确认数据是否存在以及分配:

F12 confirmed data exists and assigned

AG-grid.js内,该行就抱怨,但rowData有数据: rowData has data inside of ag-grid.js where the error complains about

+0

如果我拿出树数据分组的东西,它会显示在网格中的父级的数据。 – Jeb50

+0

是因为有些孩子里面没有内容吗? – Jeb50

+0

看到这个http://stackoverflow.com/questions/42605168/ag-grid-try-to-make-tree-demo-work-using-own-data – Jeb50

回答