[英]populate dynamically created html table in dojo and javascript
在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文件獲取結果之前先創建表。 我該如何扭轉這種狀況,以便我可以在創建表之前獲取內容?
道場很新!
正如你已經寫的
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.