我有一个D3函数,可在页面上创建列表项。我希望通过JQuery UI mobile对其进行样式设置,但是当我以多种方式调用该函数时,永远都不会对其进行样式设置。
D3 / JS:
var sampdata = [{itemname: "Placeholder0", numvalue: "$000,000"},
{itemname: "Placeholder1", numvalue: "$543,600"},
{itemname: "Placeholder2", numvalue: "$9,200"},
{itemname: "Placeholder3", numvalue: "$5,100"}];
setupgui: function()
{
d3.select("#SampcoISrevenues").selectAll("li")
.data(sampdata)
.enter()
.append("li")
.text(function (d){return d.itemname;})
.append("span")
.attr("class", "right")
.text(function (d){return d.numvalue;});
}
在此功能中,选择保留的屏幕部分,然后从“ sampdata”中添加列表项。HTML:
<body onload="Samplegui.setupgui()">
<div data-role="content">
<ul data-role="listview" data-divider-theme="a" id="SampcoISrevenues">
</ul>
</div>
</body>
我同时引用了D3库,我的index.js和JQuery(JQmobile.css / .js,JQ.js):
<link rel="stylesheet" href="../../css/jquery.mobile-1.4.2.css">
<link rel="stylesheet" href="../../css/index.css">
<script src="../../js/jquery-1.11.1.js"></script>
<script src="../../js/jquery.mobile-1.4.2.js"></script>
<script src="../../js/d3.js"></script>
<script src="../../js/yourdata.js"></script>
尽管D3函数立即运行,但JQuery mobile不会对其设置样式。我想对其进行样式设置,因为它在移动设备中确实非常有效。
您可以使用JQuery的.ready()运行该函数:
$(document).ready(Samplegui.setupgui());
这是我尝试过的方法,但是问题是我在加载实际的HTML代码之前就运行了D3函数,因此D3无法找到正确的ID /标记。黏着
`<script>
$(document).ready(Samplegui.setupgui());
</script>`
在页面底部解决了它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句