0
class FoursquareSearch.Views.Origin extends Backbone.View
events:
'change [name=origin]': 'setOrigin'
'click [name=geolocate]' : 'geolocate'
geolocate: ->
navigator.geolocation.getCurrentPosition(@handle)
handle: (response) ->
@model.set(coords: response)
我试图确定设备的位置,然后设置与响应模型视图。不过我得到
Uncaught TypeError: Cannot call method 'set' of undefined
奇怪的是这只发生在它的这个函数里面。例如,如果我使用:
geocode: (location) ->
data =
location: location
$.ajax(
type: 'POST'
url: '/search/geocode'
data: data
dataType: 'json'
error: (jqXHR, textStatus, errorThrown) =>
alert("ERROR")
success: (response, text, xhr) =>
@model.set(coords: response)
@center(@model.get('coords'))
)
里面它的工作原理相同的观点,以及它工作得很好。不过我只是不能得到其他功能设置模式。我认为这是关于它异步的东西。我绝不是这方面的专家,我正在捡拾Backbone,但是这让我难受!
这真棒谢谢 –