Tôi đã tìm ra câu trả lời. Vấn đề chính là D3 không có hàm trigger
rõ ràng như jQuery. Tuy nhiên, bạn có thể mô phỏng nó.
Giả sử bạn có một con đường D3 được xây dựng qua
d3.json("us-counties.json", function(json){
thisObj._svg.selectAll("path")
.data(json.features)
.enter().append("path")
.attr("d", thisObj._path)
.attr("class", "states")
.attr("id", function(d){
return d.id; //<-- Sets the ID of this county to the path
})
.style("fill", "gray")
.style("stroke", "black")
.style("stroke-width", "0.5px")
.on("dblclick", mapZoom)
.on("mouseover", mapMouseOver)
.on("mouseout", mapMouseOut);
});
và xử lý sự kiện mouseover rằng những thay đổi điền và đột quỵ màu
var mapMouseOver(d){
d3.selectAll($("#" + d.id))
.style("fill", "red")
.style("stroke", "blue");
}
Thông thường, hầu hết các hướng dẫn nói để sử dụng
d3.select(this)...
nhưng thực sự sử dụng giá trị hoạt động là tốt. Nếu bạn có một xử lý sự kiện mà được bạn ID của nút, và kích hoạt nó thông qua
$("#someDropdownSelect").change(someEventHandler)
function someEventHandler(){
//get node ID value, sample
var key = $(this)
.children(":selected")
.val();
//trigger mouseover event handler
mapMouseOver({id : key});
}
sẽ thực hiện sự kiện mouseover dựa trên sự lựa chọn thả xuống
Điều này hoạt động hoàn hảo. –