[英]How to call controller action from d3.js or any javascript in rails
I am trying to understand how I can call a controller action when a user presses a circle in my d3.js graph. 我试图了解当用户按下d3.js图形中的圆圈时如何调用控制器动作。 The idea is that the controller action should show more information about that circle from a database but really what I'm interested in is how to call any rails controller action from a user's click. 这个想法是,控制器动作应该从数据库中显示有关该圆圈的更多信息,但我真正感兴趣的是如何通过用户的点击调用任何rails控制器动作。 I haven't put the controller code in because I'm really just interested in how the call is made. 我没有放入控制器代码,因为我真的只是对调用的方式感兴趣。
The relevant part of my javascript looks like: 我的javascript的相关部分如下所示:
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", function(d) { return d.group * 3; })
.style("fill", function(d) { return color(d.group); })
.call(force.drag)
.on('click', connectedNodes)
.on("dblclick",getprofile(d));
function getprofile(d){
$.ajax({
url: "/users/show" ,
type: "GET",
data : { name: JSON.stringify(d.name) }
});
像这样定义dblclick
:
.on("dblclick", getprofile);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.