简体   繁体   中英

Data shows in dojo dgrid only with renderArray

With the following code fragment, the grid shows only column headers. To show the data, I need to add the last line. Why renderArray is needed for the data to show in the grid?

        var data = [
            { first: 'Bob', last: 'Barker', age: 89 },
            { first: 'Vanna', last: 'White', age: 55 },
            { first: 'Pat', last: 'Sajak', age: 65 }
        ];
        var store = new Memory({ data: data });
        var grid = new OnDemandGrid({
            collection: store,
            columns: {
                first: 'First Name',
                last: 'Last Name',
                age: 'Age'
            }
        });
        grid.startup();
        //grid.renderArray(data);

Which version of the API are you using? I simply copy/pasted your code into a JSFiddle referencing the 4.1 API and it seems to work just fine:

https://jsfiddle.net/shenningsgard/udxkuqr1/3/

HTML:

<div id="myGrid"></div>

JS:

require(['dgrid/OnDemandGrid', 'dstore/Memory'], function(OnDemandGrid, Memory) {

  var data = [{
    first: 'Bob',
    last: 'Barker',
    age: 89
  }, {
    first: 'Vanna',
    last: 'White',
    age: 55
  }, {
    first: 'Pat',
    last: 'Sajak',
    age: 65
  }];
  var store = new Memory({
    data: data
  });
  var grid = new OnDemandGrid({
    collection: store,
    columns: {
      first: 'First Name',
      last: 'Last Name',
      age: 'Age'
    }
  }, 'myGrid');
  grid.startup();
});

Result:

First Name  Last Name   Age
Bob         Barker      89
Vanna       White       55
Pat         Sajak       65

回答我的问题:引用dgrid1目录而不是dgrid。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM