简体   繁体   English

如何在ember.js 1.6.x中创建无路由子状态

[英]How to create route-less substates in an ember.js 1.6.x

I would like to create something like an admin sub-application that is available on every page of my existing ember 1.6.x app. 我想在我现有的ember 1.6.x应用程序的每个页面上创建类似管理子应用程序的东西。 It will have it's own state-machine (router) allowing it to load different controllers/templates depending on it's own state. 它将拥有自己的状态机(路由器),允许它根据自己的状态加载不同的控制器/模板。 I have seen a lot of similar discussions that revolve around having multiple state machines (routers) or extensive use of sub-routes but nothing really hit's the nail on the head. 我已经看到很多类似的讨论围绕着拥有多个状态机(路由器)或大量使用子路由,但没有任何真正的打击。

Is there a clear way to create what is in effect two ember apps on the same page? 有没有一种明确的方法可以在同一页面上创建两个有效的应用程序?

The sub-app does not need to actually have routes that are interpreted in the url bar. 子应用程序不需要实际拥有在url栏中解释的路由。 It also does not need to have it's state maintained when the parent app changes routes/states. 当父应用程序更改路由/状态时,它也不需要保持状态。 It can be reset every time the parent app changes to a different route. 每次父应用程序更改为其他路由时,都可以重置它。 What I want to avoid is repeating the same code over and over again inside multiple controllers in the parent app. 我想避免的是在父应用程序的多个控制器中反复重复相同的代码。 I would also like to avoid polluting the application or global levels. 我还想避免污染应用程序或全局级别。

Below is a list of discussions that I have looked into. 以下是我研究过的讨论列表。 The closest thing that I can find that makes sense is the work on ember flows (which has not been finished yet). 我能找到的最接近的事情是有关ember流程的工作(尚未完成)。 Or should I literally be looking into creating a new state-machine via the ember-states plugin for the sub-app? 或者,我是否应该通过子应用程序的ember-states插件来创建一个新的状态机?

To be clear I am not looking for someone to write the code for me. 要明确我不是在找人为我编写代码。 Just a discussion on how this SHOULD be done with ember 1.6.x as it is currently available. 只讨论如何使用ember 1.6.x来完成它,因为它目前是可用的。

http://discuss.emberjs.com/t/route-less-substates/2269 http://discuss.emberjs.com/t/route-less-substates/2269

http://discuss.emberjs.com/t/is-there-a-reason-we-can-not-have-nested-routes/1845 http://discuss.emberjs.com/t/is-there-a-reason-we-can-not-have-nested-routes/1845

Sending action to Ember.StateManager : is goToState mandatory? 向Ember.StateManager发送动作:goToState是强制性的吗?

https://github.com/emberjs/ember.js/issues/406 https://github.com/emberjs/ember.js/issues/406

https://github.com/emberjs/ember.js/issues/4767 https://github.com/emberjs/ember.js/issues/4767

http://discuss.emberjs.com/t/concurrent-states-in-ember/5042 http://discuss.emberjs.com/t/concurrent-states-in-ember/5042

https://github.com/nathanhammond/ember-flows-generator https://github.com/nathanhammond/ember-flows-generator

https://github.com/emberjs/ember.js/issues/406#issuecomment-3702356 https://github.com/emberjs/ember.js/issues/406#issuecomment-3702356

This could be what you are looking for: 这可能是你正在寻找的:

https://github.com/tildeio/conductor.js https://github.com/tildeio/conductor.js

我想你可以使用query-params我没有完全得到你的用例但是请查看http://instructure.github.io/ic-tabs/query-params.html#/?country=2&food=2

You can run multiple embedded isolated Ember apps inside another Ember app. 您可以在另一个Ember应用程序中运行多个嵌入式隔离Ember应用程序。

An embedded Ember app can manipulate URL state like any other app or you can configure it to have routing states but not interact with URL. 嵌入式Ember应用程序可以像任何其他应用程序一样操纵URL状态,或者您可以将其配置为具有 路由状态但不与URL交互。

Take a look at embedding applications documentation . 看一下嵌入应用程序文档

Excerpt: 摘抄:

App = Ember.Application.create({
  rootElement: '#app'
});

App.Router = Ember.Router.extend({
  location: 'none' // To disable manipulating URL
});

You can also share code between apps. 您还可以在应用之间共享代码。 For example to share an Ember Data model. 例如,共享Ember Data模型。

var MainApp     = Ember.Application.create({});
var AdminApp    = Ember.Application.create({rootElement: '#admin-container'});

AdminApp.Router = Ember.Router.extend({location: 'none'});

MainApp.User    = DS.Model.extend({});
AdminApp.User   = MainApp.User;

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

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