试图找出如何在Ember中设置此链接

时间:2013-12-15 02:50:08

标签: ember.js

我正在看Ember看它是否合适。出现的一个问题是我们有很多'狭窄'的api调用 - 这些调用返回一个包含最小数据的列表来创建一个列表,然后用户点击一个链接进入详细视图。由于链接到帮助程序的工作方式,这将绕过路径中的模型方法。这个问题有同样的问题:Transition from one route to another with a different model in Emberjs但我老实说不明白他提供的答案。具体来说,他提供了这段代码:

<a {{bindAttr href="somePropertyInYourModel"}}>{{someTextProperty}}</a>

并说:

The property somePropertyInYourModel is a property containing the url to the new page. If the url is in the ember routes it will be as if you where typing that address in the address bar and pressing enter, but without the full reload of the page.

我真的不明白他在说什么(我对此有错)。我尝试过<a {{bindAttr href="{{post}}"}}>{{someTextProperty}}</a><a {{bindAttr href="{{post}}"}}>{{someTextProperty}}</a>  但无济于事。说我有这个模型:

Hex.Post = Ember.Object.extend({
    id: null,
    body: null,
    isEnabled: null,
    createdAt: null
});

我怎么能让这个工作?他告诉我们要做什么?

thx求助,ember看起来很酷但有很多要知道

编辑#1

这是整个路由器列表。我希望有一个帖子视图,当用户点击时,它会转到将填充到右侧的帖子视图。问题是链接绕过模型,所以我们真的需要在那时重新加载模型。这将使我们能够重新利用现有的api。请求帮助

Hex.Router.map(function() {
  // put your routes here
    this.resource('index', { path: '/' });
    this.resource('users', { path: 'users' });
    this.resource('loginslogouts', { path: 'loginslogouts' });
    this.resource('locations', { path: 'locations' });
    this.resource('flaggedcontent', { path: 'flaggedcontent' });
    this.resource('posts', function(){
        this.resource('post', { path: ':post_id' });
    });
    this.resource('comments', { path: 'comments' });

});

1 个答案:

答案 0 :(得分:1)

啊,发送id而不是模型,将重新触发模型钩子。将模型发送到钩子使得ember认为你有模型,发送一个id告诉ember用该id命中模型钩子。

{{#link-to 'post' post.id}}{{post.name}}{{/link-to}}