[英]populate dynamically created html table in dojo and javascript
in html i'm dynamically creating a table: 在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;
}
I want to populate this table with data retrieved from a CSV file so i wrote the following code: 我想用从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();
});
in this case, the table gets created before i'm able to obtain the results from the csv file. 在这种情况下,在我能够从csv文件获取结果之前先创建表。 How to i reverse this so i can grab the contents just before going to create the table?
我该如何扭转这种状况,以便我可以在创建表之前获取内容?
Very new to Dojo! 道场很新!
As you already wrote 正如你已经写的
objectStore.query().then(function(results)
{
//results contains everything from csv file
});
it's deferred/async action, you need to create it when it finishes query something like 这是延迟/异步操作,您需要在查询完成后创建它
objectStore.query().then(lang.hitch(this, function(results) {
//results contains everything from csv file
this.createTable();
}));
where lang is dojo/_base/lang lang是dojo / _base / lang
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.