- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在下面有这个代码。有两个 .attr 添加到“路径”中,它们使用相同的功能。是否可以将此代码转换为一个循环,在该循环中我只能调用一次函数并使用两个 .attr 的值?
var edges = svgGroup.selectAll('path .edge').data(artifacts).enter().append('path')
.attr('class',
function(d){
if (getStatusActive(d.targetName)){
return 'edge';
}else{
return 'edge_grey';
}
}
).attr('marker-end',
function(d){
if (getStatusActive(d.targetName)){
return 'url(' + markerLocation + '#arrowhead)';
}else{
return 'url(' + markerLocation + '#arrowhead_grey)';
}
}
);
我正在寻找这样的东西:
for (each element of selectAll / data(artefacts)){
var result = getStatusAcive(d.targetName);
//create with result both strings and add them to the attr
...
...
element.append('path').attr('class', resultString1).attr('marker-end',resultString2);
);
谢谢!
最佳答案
由于字符串的值取决于数据,因此您无法像您想要的那样替换它。但是,您可以在单独的步骤中计算该字符串,将其绑定(bind)到数据,然后使用它,即
data.forEach(function(d) {
if (getStatusActive(d.targetName)){
d.resultString1 = "edge";
d.resultString2 = 'url(' + markerLocation + '#arrowhead)';
}else{
d.resultString1 = "edge_grey";
d.resultString2 = 'url(' + markerLocation + '#arrowhead_grey)';
}
});
sel.attr("class", function(d) { return d.resultString1; })
.attr("marker-end", function(d) { return d.resultString2; })
关于javascript d3 selectAll 转换为循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20400660/
为什么 d3.selectAll('rect')... 不能像下面脚本中的 mouseover 函数那样工作,但是 svg.selectAll('rect').. . 是吗? svg 是 r2d3 的
谁知道有什么区别? 我的理解是两者都会返回相同的选择。 但是,当我进行追加时,如果我使用 selectAll("p") 它不起作用。 例如,这个有效: var foo = d3.select("bod
我有以下 html 页面: var check = 0; function doNow() { void(d=document); void(el=d.getElementsBy
请参阅下面的 JavaScript: function Test() { alert('got here'); } function SelectAll() { var fr
我使用了 selectAll() 函数,但它似乎什么也没做。有没有办法让文本突出显示,这样他们就不必退格然后重新输入? void GetQuantity() { AlertDialog.Bui
我一直在玩示例 "Using D3.js to present XML as HTML Table" , 尝试学习 D3.js API。我想我已经掌握了窍门,但我无法真正理解 .selectAll()
我已经初始化了一个具有 id example 的数据表,如下所示 - var table = $("#example").DataTable({ "aaSorting": [[4, "asc"
根据一些问题的答案,我已将“本地化 native 开发区域”更改为“中国”,但是当我调试应用程序时,我在标题中列出的按钮文本仍然是英文任何其他我应该做的事情怎样解决这个问题? 最佳答案 答案是: 更改
我的 asp.net mvc Web 应用程序中有以下 Razor View :- foreach (var item in Model) { @Html.Action
是否可以使用 selectAll 在 D3 中选择多个选择器? 我想要像 svg.selectAll("class1", "circle", "id2") 这样的东西来选择所有 circle 元素,c
我正在使用 Vaadin,并且在表单中有一组文本字段。文本字段具有 focusListeners,它会触发一个方法,该方法将文本字段中的所有文本(如果有)聚焦。 我的问题是,自动选择实际上有一半的时间
根据 中的列选择显示数据表中的列. 在该列选择中,当我单独选中所有复选框时,应选中 selectAll。 当用户单独选择数据表所有复选框列切换器时,如何检查 SelectAll? 数据表中的切换器代
我有这段代码: var series, seriesChildren; selection.each(function (data) { series = d3.select(this).se
我有一个选择 g 标签的变量(我们称她为 all_g)。我想选择这个 g 的一些内容。 所以这是我的 g 标签中的内容: The G-tag 我想覆盖所有其他 afterText 内容,例如这个包含“
我正在尝试理解 source code for d3 selectAll我不明白下面我的评论之后的那一行。 我可以看到选择器字符串上有一个闭包,并且在调用 d3_selectAll 时 this 设置
我有很多不同的 JFormattedTextFields 以及操作和按键监听器。每个字段都有一个按键监听器,因此当我按 Enter 键时,我将关注下一个 JFormattedTextField。问题是
我正在尝试实现一个必须遵守以下规则的 JTable: 只能编辑第 3 列的单元格。 双击X行的任意单元格,X行第3列开始编辑。 每当开始编辑一个单元格时,它里面的文本就会被选中。 我有一个扩展 JTa
最初我有一个来自 csv 的平面哈希结构,它具有以下字段: zoneId,op,metricName,value 然后我把它嵌套在 d3.nest() .key(function(d){retur
我正在学习 D3,以及如何使用 D3 的数据绑定(bind)机制将元素嵌套或附加到页面。 我修改了在 http://www.recursion.org/d3-for-mere-mortals/ 上找到
我正在研究以下径向图: //Fade out all players except the first player g.selectAll(".teamArc")
我是一名优秀的程序员,十分优秀!