简体   繁体   English

事件+ jshint上的d3.js可能严格违反

[英]d3.js on event + jshint possible strict violation

I have an on mouseover event handler bound to a bar chart rect svg objects. 我有一个绑定到条形图svg对象的on mouseover事件处理程序。

 svg.selectAll('.bar')
    .data(data)
    .enter()
    .append('rect')
    .on('mouseover', mouseover)
    .on('mouseout', mouseout)
    .attr('class', 'bar')
    .attr('x', 0)
    .attr('y', function(d) { return y(d[keyName]); })
    .attr('height', y.rangeBand())
    .attr('width', function(d) { return x(d[valueName]); })
    .attr('val', function(d) { return d[valueName]; });

I call the mouseover function which gets gets the rect object that the user is hovering over and pulls some values along with setting the fill style. 我调用mouseover函数,该函数获取用户悬停在其上的rect对象,并获取一些值以及设置填充样式。 Everything is working as aspected but when I run jshint it warns me about "Possible strict violation" on my use of this . 一切工作aspected但是当我运行jshint它警告我,“可能违反了严格的”我用this Any idea on how to get this lint case to pass with D3? 关于如何使此皮箱通过D3的任何想法?

function mouseover() {
var val = d3.select(this).attr('val');

div.transition()
    .duration(200)
    .style('opacity', 0.9);

div.html(val + ' Servers')
    .style('left', (d3.event.pageX + 20) + 'px')
    .style('top', (d3.event.pageY - 20) + 'px');

d3.select(this).style('fill', 'brown');
}

Use function expression instead of declaration like 使用函数表达式而不是像这样的声明

var mouseover = function () {
var val = d3.select(this).attr('val');

div.transition()
    .duration(200)
    .style('opacity', 0.9);

div.html(val + ' Servers')
    .style('left', (d3.event.pageX + 20) + 'px')
    .style('top', (d3.event.pageY - 20) + 'px');

d3.select(this).style('fill', 'brown');
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM