从控制器获取标记以使用 gmaps4rails 刷新地图

发布于 2024-12-05 07:36:18 字数 252 浏览 2 评论 0原文

我有一个使用 gmaps4rails 在 Rails3 应用程序中具有多个标记的应用程序。

地图最初加载了所有标记,但我在页面上有一个过滤器字段,我希望用户过滤存储在数据库中的标记的不同内容。

如何触发地图以使用参数调用控制器,该参数将返回一个新的 json 对象,然后将其放入 Gmaps4Rails.replaceMarkers 函数中?

我正在使用 JQuery,因此最好从 Jquery 代码触发此行为。

问候, 约翰

I have an app with multiple marker in a Rails3 application using gmaps4rails.

The map is loaded initially with all the markers but I have a filter fields on the page which I would like the user to filter different things which are stored in the db for the markers.

How to I trigger the map to call the controller with the parameters which would return a new json object, which I would then put in Gmaps4Rails.replaceMarkers function?

I'm using JQuery so it would probably be best to trigger this behavior from Jquery code.

Regards,
Johann

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光下的微笑 2024-12-12 07:36:18

为什么不为这些过滤器字段(或在提交按钮中)设置一个事件侦听器,然后通过 AJAX 在服务器上调用 your_controller ?

$("#yourSubmitButton").click(function() {
  $.getJSON('/get_markers.json', { filter: "value" }, function(json) {
    Gmaps.map.serviceObject.replaceMarkers(json);
  });
});

未测试代码。

Why don't you just set a event listener to those filter fields (or in a submit button), that then calls your_controller at the server via AJAX?

$("#yourSubmitButton").click(function() {
  $.getJSON('/get_markers.json', { filter: "value" }, function(json) {
    Gmaps.map.serviceObject.replaceMarkers(json);
  });
});

Didn't test the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文