在Emberjs中以不同的模式从一条路线转换到另一条路线 [英] Transition from one route to another with a different model in Emberjs

查看:117
本文介绍了在Emberjs中以不同的模式从一条路线转换到另一条路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索页,我们得到不同类型的搜索结果。在搜索结果列表中,我想使用

  {{#linkTo'someResources.someResource'result}} {{result .Name}} {{/ linkTo}} 

在路由 someResources .someResource 我想使用与搜索页面完全不同的模型。我怎么做?当我点击 linkTo 的链接时,它不会再次加载模型,而是尝试使用名为 result 这里。



所以我想做的是在我导航到 someResources.someResource 的时候重新加载模型,基于 result 中的值



我有一个名为 App.SomeResource的模型和一个find方法,如果我直接去那个页面,它可以工作。

解决方案

由于问题是当我使用 linkTo 进行转换时,我想要完全重新加载模型,因为这是使用给定的模型。问题的解决方法实际上很简单,只是使用一个常规的html a -tag。我最终做的是这样的:

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

属性 somePropertyInYourModel 是一个包含url到新页面。如果网址在垃圾路线中,那么就像在地址栏中输入地址一样,然后按Enter键,但没有完全重新载入页面。



我认为这是一个可以改进的东西,如果我可以写一些类似的东西,那将会更好:

  {{ #linkToRouteresourceA.routeBparams =val1,val2,val3}}去这里{{/ linkToRoute}} 

由于我设置了这个路由:

  App.Router.map(function(){
this.resource(resourceA,{{path:/ resourceA}},function(){
this.route(routeB,{{path:/:prop1 /:prop2 /:prop3 );
}
});

我想得到:

 < a href =#/ resourceA / val1 / val2 / val3>去这里< / a> 

val1,val2,val3 的顺序如果订单被更改,他们也应该在最终的url中更改。


I have a search page where we are getting different types of search results. In the list of search results I would like to use

{{#linkTo 'someResources.someResource' result}}{{result.Name}}{{/linkTo}}

And on the route someResources.someResource I want to use a totally different model than on the search page. How do I do that? When I click on the link for the linkTo it doesn't load the model again, instead it tries to use the model named result here.

So what I would like to do is to reload the model when I navigate to someResources.someResource based on the values in result.

The I do have a model named App.SomeResource and a find method for it that works if I go directly to that page.

解决方案

Since the problem is that I want a full reload of the model when doing the transition using linkTo won't work since that is using the model given to it. The solution to the problem is actually quite simple, just use a regular html a-tag instead. What I ended up doing was this:

<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.

I think this is something that could be improved in ember, it would be much nicer if I could write something like:

{{#linkToRoute "resourceA.routeB" params="val1,val2,val3"}}Go here{{/linkToRoute}}

given I have this routes set up:

App.Router.map(function() {
    this.resource("resourceA", {{path: "/resourceA"}}, function() {
        this.route("routeB", {{path: "/:prop1/:prop2/:prop3");
    }
});

I would like to get:

<a href="#/resourceA/val1/val2/val3">Go here</a>

The order of the val1,val2,val3 matters, if the order is changed they should also be changed in the final url.

这篇关于在Emberjs中以不同的模式从一条路线转换到另一条路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆