[英]Using D3 or JQuery to update a d3 created screen
I'm using d3 to create a few list items on my screen, and when I click a button I need it to run again as if the first time it ran had never happened. 我正在使用d3在屏幕上创建一些列表项,当我单击一个按钮时,我需要它再次运行,好像第一次运行从未发生过。
setupgui: function()
{
d3.select("#SampcoISrevenues").selectAll("li")
.data(function () {
if($("#radio-choice-h-2a").is(":checked"))
{
return sampleQ1;
}
else if($("#radio-choice-h-2b").is(":checked"))
{
return sampleQ2;
}
else if($("#radio-choice-h-2c").is(":checked"))
{
return sampleQ3;
}
else if($("#radio-choice-h-2d").is(":checked"))
{
return sampleQ4;
}
})
.enter()
.append("li")
.attr("class", function (d){return d.textcolor;})
.text(function (d) {
var indentvalstring = "";
for(var i = 0; i < d.indentval; i++)
{
indentvalstring += "\u00a0";
}
indentvalstring += d.itemname;
return indentvalstring;
})
.append("span")
.attr("class", "right")
.text(function (d){return d.numvalue;});
}
when this is run, it loads data in from the array and depending on the button that is checked it outputs it. 运行此命令时,它将从数组中加载数据,然后根据选中的按钮将其输出。 When I select another button for a different set of data, it does not do anything.
当我为另一组数据选择另一个按钮时,它不会执行任何操作。 Is there a way to remove the data onscreen and replace it with the one selected from the button?
有没有办法删除屏幕上的数据并将其替换为从按钮中选择的数据?
D3 provides the .remove()
function to remove all elements in a selection from the DOM. D3提供
.remove()
函数,以从DOM中删除所选内容中的所有元素。 All you need to do is select those elements and then call the function: 您需要做的就是选择这些元素,然后调用该函数:
d3.select("#SampcoISrevenues").selectAll("li").remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.