Javascript 传单弹出表单:在弹出表单提交中包含传单latlong值

Javascript 传单弹出表单:在弹出表单提交中包含传单latlong值,javascript,jquery,ruby-on-rails-4,leaflet,leaflet.draw,Javascript,Jquery,Ruby On Rails 4,Leaflet,Leaflet.draw,我有一个使用传单的弹出表单,希望将eventLatLong值作为提交参数的一部分。 因此,我画一个多边形或放置一个标记,弹出窗口应该显示一个表单,用户在其中输入一个名称。此名称需要与绘制事件坐标一起保留 这就是我到目前为止所用的代码,我花了数小时试图弄明白这一点。一般来说,我对JQuery、Ajax和JS这样的前端技术非常陌生,因此非常感谢您的帮助 <script> map.on(L.Draw.Event.CREATED, function (e) { eventLatLon

我有一个使用传单的弹出表单,希望将eventLatLong值作为提交参数的一部分。 因此,我画一个多边形或放置一个标记,弹出窗口应该显示一个表单,用户在其中输入一个名称。此名称需要与绘制事件坐标一起保留

这就是我到目前为止所用的代码,我花了数小时试图弄明白这一点。一般来说,我对JQuery、Ajax和JS这样的前端技术非常陌生,因此非常感谢您的帮助

<script>
map.on(L.Draw.Event.CREATED, function (e) {
    eventLatLong = e.layer._latlng;
    var polyEvent = drawnItems.addLayer(e.layer);
    var popupForm = '<form class="simple_form business_form" id="form" novalidate="novalidate" enctype="multipart/form-data" action="/create_section" accept-charset="UTF-8" data-remote="true" method="post" _lpchecked="1"><input name="utf8" type="hidden" value="✓">\n' +
        '    <h2>\n' +
        '<input id="coords" type="hidden" value="">\n' +
        '        <div class="input string required thing_part_name"><label class="string required control-label" for="thing_part_name" id="name"><abbr title="required">*</abbr> Name</label><input class="string required" autofocus="autofocus" type="text" name="thing_part[name]" id="thing_part_name"></div>\n' +
        '        <div class="form-actions">\n' +
        '            <input type="submit" name="commit" value="Add New Poly">\n' +
        '        </div>\n' +
        '        <br>\n' +
        '    </h2>\n' +
        '</form>';
    polyEvent.bindPopup(popupForm, {
        keepInView: true,
        closeButton: true
    }).openPopup();

    $("#form").submit(function (e) {
        e.preventDefault();
    });
});
</script>

map.on(L.Draw.Event.CREATED,函数(e){
eventLatLong=e.layer.\u latlng;
var polyEvent=drawnItems.addLayer(e.layer);
var popupForm='\n'+
“\n”+
“\n”+
“*名称\n”+
“\n”+
“\n”+
“\n”+
“
\n”+ “\n”+ ''; polyEvent.bindPopup(弹出窗体{ 基平维尤:没错, 关闭按钮:真 }).openPopup(); $(“#表格”)。提交(功能(e){ e、 预防默认值(); }); });
我想出来了

我所要做的就是通过jquery的
val
函数传递数据

<script>
map.on(L.Draw.Event.CREATED, function (e) {

    var polyEvent = drawnItems.addLayer(e.layer);

    theBounds = JSON.stringify(e.layer.toGeoJSON())

    var popupForm = '<%= j render "path/to/form" %>';

    polyEvent.bindPopup(popupForm, {
        keepInView: true,
        closeButton: true
    }).openPopup();

    $('#bounds').val(theBounds);

    $("#form").submit(function (e) {
        e.preventDefault();
    });
});
</script>

map.on(L.Draw.Event.CREATED,函数(e){
var polyEvent=drawnItems.addLayer(e.layer);
theBounds=JSON.stringify(e.layer.toGeoJSON())
var popupForm='';
polyEvent.bindPopup(弹出窗体{
基平维尤:没错,
关闭按钮:真
}).openPopup();
$('边界').val(边界);
$(“#表格”)。提交(功能(e){
e、 预防默认值();
});
});