当我将jQuery UI Datepicker放入Google Map Infowindow时,我遇到了问题。
我们正在建立一个有多个目的地的行程经理。每个目的地都有一个到达和离开日期,每个都有一个日期选择器。您可以在两个位置设置这些日期,位于页面底部的“itinerary”div和Google Map上的InfoWindow内。日期选择器在行程中正常工作,但日历不会显示在Google地图信息窗口内。
使用以下两种方法动态创建和更新Infowindows:
#opens the infowindow associated with destination
openInfowindow: (destination, map) =>
info_content = @_generateInfowindowHTML(destination)
if not @infowindow #infowindow not defined
@infowindow = new google.maps.InfoWindow
content: info_content
else #infowindow already created
@infowindow.setContent(info_content)
@infowindow.open(map, destination.marker)
#produces the HTML content for the infowindow association with destination
_generateInfowindowHTML: (destination) =>
iw = $('#infowindow-template').clone(true).removeClass('hidden').removeAttr('id')
iw.find('h5').text(destination.formatted_address) #infowindow header, formatted address
iw.find('.infowindow-content').attr('data-destination-uid', destination.uid)
iw.find('.infowindow-content').attr('id', 'infowindow-uid-' + destination.uid)
#Setting date pickers for destinations
#NOTE: All datepickers need unique ids
iw.find('.destination-arrival-date-picker').attr('id', 'infowindow-destination-arrival-datepicker-uid-' + destination.uid)
iw.find('.destination-arrival-date-picker').datepicker
autosize: true
dateFormat: "M d, yy"
onSelect: (date, input) ->
console.log 'selected arrival date!'
iw.find('.destination-departure-date-picker').attr('id', 'infowindow-destination-departure-datepicker-uid-' + destination.uid)
iw.find('.destination-departure-date-picker').datepicker
autosize: true
dateFormat: "M d, yy"
onSelect: (date, input) ->
console.log 'selected departure!'
return iw.html()
有问题的HTML:
<!-- Info window template -->
<div id="infowindow-template" class="hidden">
<div class="infowindow-content" data-destination-uid="">
<h5>Location Name</h5>
<div class="block info-date-container link-text">
<div class="add-destination-date">
<i class="fa fa-calendar-plus-o"></i> <span>Add Dates</span>
</div>
<div class="edit-destination-date-div hidden inline-block">
<i class="fa fa-calendar-plus-o fa-fw in-form-icon"></i>
<%= text_field_tag '', nil, :class => 'date-picker destination-date-picker destination-arrival-date-picker',
:placeholder => 'Arrival Date' %>
<i class="fa fa-calendar-plus-o fa-fw in-form-icon"></i>
<%= text_field_tag '', nil, :class => 'date-picker destination-date-picker destination-departure-date-picker',
:placeholder => 'Departure Date' %>
<i class="fa fa-check confirm-destination-dates icon--confirm"
data-toggle="tooltip" data-placement="right" title="Confirm Dates"></i>
</div>
<div class="destination-date-wrapper hidden inline-block">
<span class="destination-arrival-date"> ? </span>
<span> to </span>
<span class="destination-departure-date"> ? </span>
<i class="fa fa-pencil edit-destination-date" data-toggle="tooltip" data-placement="below" title="Change Dates"></i>
</div>
</div> <!-- End Info Date Container -->
</div>
</div>
我们的调查到目前为止:
$('#datepicker-id').datepicker()
),但这不起作用。类似的主题:
答案 0 :(得分:2)
在_generateInfowindowHTML()
中,您必须返回iw[0]
而不是iw.html()
。当你返回html它只是一个字符串时,你将失去已添加到元素及其子元素的所有功能。