简体   繁体   English

如何从第三方库切换/转换Ember路由?

[英]How to switch/transition an Ember route from third party library?

I'm having difficulty integrating Ember.js with a third party control (fancytree). 我在将Ember.js与第三方控件(fancytree)集成时遇到困难。 In this case, I want the tree nodes to show different Ember views on the main content area. 在这种情况下,我希望树节点在主要内容区域上显示不同的Ember视图。

Right now, while rendering the nodes, I'm wrapping them into a tags pointing to '#/a', '#/b', etc.. other option I though of would be using window.location = url; 现在,在渲染节点时,我将它们包装到一个指向'#/ a','#/ b'等的标签中。其他选项我将使用window.location = url; to switch to the appropriate route. 切换到适当的路线。

It's working but I'm learning Ember and would like to know if this is the best way of doing this.. 它正在运行,但是我正在学习Ember,想知道这是否是最好的方法。

Is there an 'Ember' way of doing this? 有没有一种“灰烬”的方式做到这一点? Or what I'm doing is how this is usually done? 还是我正在做的是通常如何做?

Thank you! 谢谢!

I'm not sure if my way is the correct Ember way but it is working for me. 我不确定我的方法是否是正确的Ember方法,但它对我有用。 I added in the namespace (in my case 'App') the application controller: 我在名称空间(以我的情况为“ App”)中添加了应用程序控制器:

App.ApplicationController = Ember.ObjectController.extend({
    init: function() {
        this._super();
        App.controllerHelper = this;
    },
});

You can now call with this helper the transitionToRoute method from everywhere: 现在,您可以从任何地方使用此帮助器调用transitionToRoute方法:

App.controllerHelper.transitionToRoute('your route' [, dynamic id]);

I hope this helps and please correct me if there is a better way. 我希望这会有所帮助,如果有更好的方法,请纠正我。

Use the History API . 使用History API Ember's router should be able to pick up the state changes and transition accordingly. Ember的路由器应该能够接收状态更改并进行相应的转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM