첫 번째 jQuery 플러그인을 만들려고합니다. 기본적으로 그것은 누군가가 Google지도에서 마커를 움직일 때마다 일부 위도 및 경도 텍스트 필드를 업데이트하는 goMap지도에 대한 래퍼와 같습니다.다른 jQuery 플러그인을 사용하는 jQuery 플러그인을 만드는 방법은 무엇입니까?
는 나는 다음과 같이 설정이 (내가 질문을 작성할 때이 이렇게 누락 된 세미콜론을 무시하거나 내가 coffeescript에 쓴 있기 때문에 꽤 거친 모습 것입니다 그냥 번역하고 어떤하시기 바랍니다!) :
(function($) {
$.fn.correctionMap = function(options) {
defaults = {
latFieldSelector: "#listing_latitude"
longFieldSelector: "#listing_longitude"
resetLinkSelector: "#reset_marker_link"
marker_id: 'listing_marker'
}
options = $.extend(defaults, options);
// grab the text field elements
latField = $(options.latFieldSelector)
longField = $(options.longFieldSelector)
// inialise the map go-ordinates from the
// values in the text fields
initialLat = Number(latField.val())
initialLong = Number(longField.val())
// build the options object for the goMap plugin
map_options = {
longitude: initialLong
latitude: initialLat
zoom: 16
maptype: 'ROADMAP'
markers: [{
longitude: initialLong
latitude: initialLat
draggable: true
id: options.marker_id
}]
};
// add the map to the div
return this.goMap(map_options)
)(jQuery)
그럼 $("#correction_map").correctionMap()
으로 전화하면 아무 것도하지 않는 것 같습니다. 그러나 플러그인 내에서 console.log this.goMap(map_options)
이 표시되면 초기화가 잘되어있는 것처럼 보입니다 (간단 검사). 나 잘못했거나 뭔가 잘못하고있는거야?
내가보기에, 다른 플러그인에 대한 호출에서 추적을 시도 했습니까? 오류가 있습니까? 지나가는 데이터에 문제가있을 수 있습니다. –
lol 고정했습니다. 자바 스크립트가 완벽했다, 나는지도 div에게 높이와 너비를주는 것을 잊었다! 어쨌든 봐 주셔서 감사합니다. –