Backbone.js:导航路线时何时渲染视图
以下是我的骨干应用程序的要求:
- 显示用户创建的文件夹列表,
- 单击文件夹时显示文件夹的内容,
这是我的实现方式。
AppRouter = Backbone.Router.extend({
routes: {
'': 'home',
'get/:name/:id': 'contents'
},
home: function() {
// show list of folders
},
contents: function(name, id) {
// show contents of clicked folder
}
});
这种方法给我带来了问题,因为当我单击文件夹时,路由会保存在浏览器历史记录中,并且结构为“domain.com#get/folder/1”。如果我碰巧将此网址粘贴到浏览器的地址栏中,则不会呈现文件夹列表,因为它与路线不匹配。
在路由器的initialize
功能中显示文件夹列表是一个明智的策略吗?可以创建一个页面视图来检查文件夹是否已显示?
Here are the requirements for my backbone app
- display a list of folders that user has created
- display the contents of a folder when a folder is clicked
Here is how I've implemented it.
AppRouter = Backbone.Router.extend({
routes: {
'': 'home',
'get/:name/:id': 'contents'
},
home: function() {
// show list of folders
},
contents: function(name, id) {
// show contents of clicked folder
}
});
This approach is giving me problems since when I click on a folder, the route gets saved in browser history and is of the structure 'domain.com#get/folder/1`. If I happen to paste this url in the address bar of browser, the list of folders won't be rendered since it doesn't match the route.
Would it be a smart strategy to display the list of folders in initialize
function of router? may be create a page view which checks if the folders have already been displayed or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,文件夹列表应该永久显示。您的应用程序有两个大视图:文件夹列表和内容。并且文件夹列表必须一直显示。
If I understand correctly, the list of folders should be shown permanently. And your application has two big views, the list of folders, and the contents. And the list of folders must be displayed all the time.