我正在搞乱异步调用。我想生成一个仪表板并用id“1”初始化它。它会生成元素,我可以单击这些元素并生成带有元素的另一个仪表板。它就像一棵树。
所以我可以生成id为1的仪表板,但我无法点击它。我知道,这是因为我的代码中的异步调用,但我不知道如何修复它。我正在乱搞Deferred Objects,但它没有帮助我。所以这是基础:
/// <reference path="jquery.d.ts" />
/// <reference path="scripts/Dashboard.ts" />
$(document).ready(function ()
{
init();
jQuery('.Reference').click(function()
{
var classId = jQuery(this).attr('class');
jQuery('#content').remove();
generateDashboard(parseInt(classId), (d: Dashboard): void =>
{
d.printDashboard();
});
});
});
function generateDashboard(param: number, callback: (d: Dashboard) => void): void
{
new Dashboard(param, callback);
}
function init()
{
generateDashboard(1, (d: Dashboard): void =>
{
d.printDashboard();
});
}
提前致谢:)
编辑:这里生成的HTML。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dashboard</title>
<link type="text/css" href="app.css" rel="stylesheet">
<script src="jquery.js">
<script src="app.js">
<script src="scripts/Helper.js">
<script src="scripts/Dashboard.js">
<script src="scripts/Elements.js">
<script src="scripts/Leaf.js">
<script src="scripts/Status.js">
<script src="scripts/Threshold.js">
<script src="scripts/Item.js">
</head>
<body>
<h1 id="dashboard"></h1>
<div id="content">
<div class="1">Element-1</div>
<div class="31">Element-4</div>
<div id="31" class="Reference">Element-2</div>
</div>
</body>
</html>