使用 Backbone.Router 记住带有 url 哈希的复杂页面状态
我目前正在尝试执行标题中所写的操作:),但找不到一个好的/干净的方法来做到这一点...
问题是:
我有一个带有地图的页面,其中包含可以通过单击显示的对象在他们身上。该地图还有一个工具栏,您可以使用它来隐藏/显示某些类别的对象以及其他类似的东西。
目前我正在使用 Backbone.Router 并通过 url 哈希为这些对象分配永久链接,例如 www.mysite.com/index/#/orange/1 -> “显示橙色数字 1”
。但现在,我还想将地图工具栏状态保存在 url 中,并且我希望所有内容都使用同一个路由器来处理!因此,最好的办法是拥有多个哈希值,例如 www.mysite.com/index/#/orange/1#/show/bananas#/hide/apples
,-> “显示橙色数字 1 - 显示所有香蕉 - 隐藏苹果”
但我知道这是不可能的......
那么,有人知道我如何使这种复杂的状态出现在url,并由骨干路由器处理?我怎样才能以干净/简单的方式处理它?
I am currently trying to do what's written in the title :) but can't find a good/clean way to do it ...
Here is the problem :
I have a page with a map, with objects that you can display by clicking on them. This map also has a toolbar, that you can use to hide/show some categories of objects, and other similar stuff.
Currently I am using Backbone.Router
and assign a permalink to those objects through url hash, e.g. www.mysite.com/index/#/orange/1
-> "show orange number 1"
. But now, I would also like to save the map toolbar state in the url, and I would like everything to be handled with the same router ! So the best thing would be to have several hashes, e.g. www.mysite.com/index/#/orange/1#/show/bananas#/hide/apples
, -> "show orange number 1 - display all bananas - hide apples"
but I know that it isn't possible ...
So, does anybody have an idea, how I could make this complex state appear in the url, and be handled by a Backbone router ? How can I handle it a clean/simple way ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道主干,但关于 URL,我会做类似的事情:
这将名词(对象名称)放在第一位,命令(N,全部,无)放在第二位,成对放置。
I don't know backbone but regarding the URL I'd do something like:
This places the noun (object name) first and the command (N, all, none) second, in pairs.