我正在构建一个应用程序,使用HTML5地理定位找到用户的位置。一旦获取了他们的位置,它们会在地图上标出(父级路由)。然后,他们可以选择查看在该位置周围发布的推文列表(子路由)。
因此,我需要将父级路由中检索到的坐标(存储在控制器上)传递给子路由,以便可以正确查询Twitter API。但是,我不确定如何做到这一点,甚至是否选择了最佳方法。
以下是索引控制器:
"WhatDoYouWantToKnow"控制器需要索引控制器。
这个路由有一个模板,链接到'/what-do-you-want-to-know/tweets'路由:
我需要将这些坐标传递给子路由:
因此,我需要将父级路由中检索到的坐标(存储在控制器上)传递给子路由,以便可以正确查询Twitter API。但是,我不确定如何做到这一点,甚至是否选择了最佳方法。
以下是索引控制器:
App.IndexController = Ember.ObjectController.extend({
coords: false,
getGeoLocation: function() {
if (navigator.geolocation) {
this.set('retrieving', true);
navigator.geolocation.getCurrentPosition(
this.locationRetrieved.bind(this),
this.locationFailed.bind(this),
{
timeout: 20000
}
);
} else {
this.set('geolocation', false);
}
},
locationRetrieved: function(position) {
this.set('coords', position.coords);
this.get('target').transitionTo('what-do-you-want-to-know');
}
});
"WhatDoYouWantToKnow"控制器需要索引控制器。
App.WhatDoYouWantToKnowController = Ember.ObjectController.extend({
needs: 'index',
createMap: function() {
var coords = this.get('controllers.index').get('coords');
var pyrmont = new google.maps.LatLng(coords.latitude, coords.longitude);
var map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 8
});
var marker = new google.maps.Marker({
map: map,
position: pyrmont
});
}
});
这个路由有一个模板,链接到'/what-do-you-want-to-know/tweets'路由:
<p>Your location:</p>
<div id="map"></div>
<ul>
<li>{{#linkTo 'tweets'}}Tweets{{/linkTo}}</li>
</ul>
我需要将这些坐标传递给子路由:
App.TweetsRoute = Ember.Route.extend({
model: function() {
return App.Tweet.find({coords:});
}
});
我正在使用Ember Data的Basic Adapter。
needs: 'index'
。 - xamenraxcontrollerFor
方法已被弃用。 - louiscoquioneeds controllerName
。 - xamenraxController#controllerFor
已经被弃用,而不是Route#controllerFor
。 - louiscoquio