简体   繁体   English

在余烬中保持多个状态

[英]Maintain multiple states in ember

Consider an ftp browser application written using Ember. 考虑使用Ember编写的ftp浏览器应用程序。 It is likely to have a perhaps a tree view for the hierarchy and a list view for the files of the current selection. 对于层次结构,可能有一个树视图,对于当前选择的文件可能有一个列表视图。 And store the current selection in the URL as: 并将当前选择存储在URL中为:

baseUrl/#path baseUrl /#path

eg 例如

www.emberftp.com/#stuff/docs/programming www.emberftp.com/#stuff/docs/programming

Not that difficult. 没有那么困难。

However! 然而! Now consider extending this application to having two browser views sort of like Windows Commander. 现在,考虑将该应用程序扩展为具有类似于Windows Commander的两个浏览器视图。 And that one view is currently browsing /stuff/docs/programming and the other /backup/images. 该视图当前正在浏览/ stuff / docs / programming,另一视图正在浏览/ backup / images。

Obviously this would require multiple outlets at some level but what happens to the URL? 显然,这将需要多个级别的出口,但是URL会如何?

First of all, is this at all supported? 首先,这是否完全受支持? If it is, how should this be set up with routes and serialization/deserialzaion? 如果是这样,应该如何设置路由和序列化/反序列化? And what would the URL actually look like? 网址实际上是什么样的?

baseUrl/#?browser1=/stuff/docs/programming&browser2=/backup/images baseUrl /#?browser1 = / stuff / docs / programming&browser2 = / backup / images

Maybe? 也许?

The Ember router will update the browser's URL to be a reflection of the current application state. Ember路由器将更新浏览器的URL以反映当前应用程序状态。 This is done so a user can return to or share his current state by a URL. 这样做是为了使用户可以通过URL返回或共享其当前状态。 It is important to note that the router can only ever be in one state at a given time. 重要的是要注意,路由器在给定时间只能处于一种状态。

The router is all about using serialization and deserialization to recreate it's state. 路由器是关于使用序列化和反序列化来重新创建其状态的。 This is basically the idea of turning the current application state into a sharable URL and vice-versa. 基本上,这是将当前应用程序状态转换为可共享URL的想法,反之亦然。 To solve the question you posted you should probably have a model, lets call it window , that has many browsers . 要解决您发布的问题,您可能应该有一个模型,将其称为window ,它具有许多browsers Then when you are loading your window via a URL you can easily reconstruct all of your ftp browsers. 然后,当您通过URL加载窗口时,您可以轻松地重建所有ftp浏览器。 I think that dealing with one model makes the serialization/deserialization process a lot easier to conceptualize. 我认为处理一个模型会使序列化/反序列化过程更容易概念化。

Anyway, here is how your models might look. 无论如何,这就是模型的外观。

App.Window.create({
  id: 1,
  browsers: [1, 2]
});

App.Browser.create({
  id: 1,
  path: "/stuff/docs/programming"
});

App.Browser.create({
  id: 2,
  path: "/backup/images"
})

And your router would only have to know how to deserialize "/windows/:window_id". 而且您的路由器只需要知道如何反序列化“ / windows /:window_id”。

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

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