我正在使用此问题的用户提示。 Ember and Anchor link.
我的问题是,我想在同一页面上链接某些内容,即索引。 但是,如果我来自印记,它不起作用,因为顶部没有定义。
app.js:
var App = Ember.Application.create({
LOG_TRANSITIONS: true
});
App.ApplicationRoute = Ember.Route.extend({
events: {
goToLink: function(item, anchor) {
var $elem = $(anchor);
var $scrollTo = $('body').scrollTop($elem.offset().top);
this.transitionToRoute(item.route).then($scrollTo); //.transitionTo is depricated
}
}
});
App.Router.map(function() {
this.route('imprint', { path: "/imprint" });
});
的index.html:
<script type='text/x-handlebars' data-template-name="application">
<a href="#/" {{action 'goToLink' "index" "#ThomasWurster"}}>Thomas Wurster</a>
</script>
<script type='text/x-handlebars' data-template-name="index">
<a id="ThomasWurster">blubb</a>
</script>
<script type='text/x-handlebars' data-template-name="imprint">
Imprint
</script>