1

在 html 中,我正在动态创建一个表:

function createTable() 
{
    var tablecontents = "";
    tablecontents = "<table>";
    tablecontents += "<tr>";

    for (var i = 0; i < 12; i ++)
    {
        tablecontents += "<td>";
        tablecontents += '<div data-dojo-type="com.Control" id="Control' + i + '" style="width: 143px; height: 200px;"/>' ;
        tablecontents += "</td>";
    }
        tablecontents += "</tr>";

    for(var z = 0; z < 12; z++) 
    {
        tablecontents += "<tr>";
        tablecontents += "<td>";
        tablecontents += 'C';
        tablecontents += "</td>";
        tablecontents += "<td>";
        tablecontents += '<div data-dojo-type="com.Control" id="ControlTwo' + z + '" style="width: 40px; height: 20px;"/>' ;
        tablecontents += "</td>";
        tablecontents += "<td>";
        tablecontents +=  'B'
        tablecontents += "</td>";
        tablecontents += "<td>";
        tablecontents +=  'A'
        tablecontents += "</td>";
        tablecontents += "<td>";
        tablecontents +=  '2010'
        tablecontents += "</td>";
        tablecontents += "<td>";
        tablecontents += '<div data-dojo-type="com.Control" id="ControlThree' + z + '" style="width: 40px; height: 20px;"/>' ;
        tablecontents += "</td>";
        tablecontents += "</tr>";
    }
      tablecontents += "</table>";
      document.getElementById("graphicalData").innerHTML = tablecontents;
} 

我想用从 CSV 文件中检索到的数据填充此表,因此我编写了以下代码:

ready(function() {

            //programmatically reading CSV from external file
            var personStoreForGrid = new dojox.data.CsvStore({
                url:"datasheet.csv"
            });

            //storing to DataStore
            var objectStore = dojo.store.DataStore({
                store: personStoreForGrid
            });

            objectStore.query().then(function(results)
            {
                //results contains everything from csv file

            });

            createTable();
            parser.parse();
}); 

在这种情况下,在我能够从 csv 文件中获取结果之前创建了表。我如何扭转这一点,以便我可以在创建表格之前获取内容?

对 Dojo 非常陌生!

4

1 回答 1

1

正如你已经写的

objectStore.query().then(function(results)
{
   //results contains everything from csv file

});

它是延迟/异步操作,您需要在完成查询时创建它

  objectStore.query().then(lang.hitch(this, function(results)  {
  //results contains everything from csv file
    this.createTable();
 }));

其中 lang 是 dojo/_base/lang

于 2013-05-30T05:34:54.667 回答