[英]Backbone application with routes from a static json file (read-only)?
I'm building a read only backbone app with data (sourced from a single static json file) that follows a building/campus structure of sort. 我正在建立一个具有数据(从单个静态json文件中获取)的只读主干应用程序,该数据遵循某种构建/校园结构。 That is: 那是:
[{
"name": "Building Name",
"id": "building",
"floors":[{
"name":"Ground Floor",
"rooms":[{
"name": "Room 1"
},
{
"name": "Room 2"
}]
},
{
"name":"First Floor",
"rooms":[{
"name": "Room 3"
},
{
"name": "Room 4"
}]
}]
},
{
"name": "Another Building",
"id": "building_2",
"floors":[{
"name":"Ground Floor",
"rooms":[{
}]
},
{
"name":"First Floor",
"rooms":[{
}]
}]
}]
I currently have a basic app set up that shows the list of buildings and floors for each building on a default '' route. 我目前有一个基本的应用程序设置,可显示默认''路线上每个建筑物的建筑物和楼层列表。
I would like to use the router so that APP/#buildingId/ shows the list of floors for a building with 'buildingId' and APP/#buildingId/#floorId shows the relevant list of rooms, etc. 我想使用路由器,以便APP /#buildingId /显示带有“ buildingId”的建筑物的楼层列表,而APP /#buildingId /#floorId显示房间的相关列表等。
JSBIN of my current code (without data.json) - http://jsbin.com/welcome/5850/edit 我目前的代码JSBIN(不data.json) - http://jsbin.com/welcome/5850/edit
Lots of code is probably obsolete, but I was trying different ways to structure the models/collections. 许多代码可能已过时,但是我正在尝试采用不同的方法来构建模型/集合。 This app will never be more than read-only which is why I went with a static file. 这个程序永远不会超过只读,这就是为什么我使用静态文件。
Similar problem: How to use JSON to power interactive Backbone.js app 相似的问题: 如何使用JSON为交互式Backbone.js应用程序提供动力
The solution presented doesn't use the Router at all. 提出的解决方案根本不使用路由器。
Is this what you are asking for?: 这是您要的吗?:
// code simplified and no tested
App.Router = Backbone.Router.extend({
routes: {
"/APP/:buildingId/:floorId": "showRooms",
"/APP/:buildingId": "showFloors"
},
showRooms: function( buildingId, floorId ) {
// code to show the rooms
},
showFloors: function( buildingId ) {
// code to show the floors
},
});
Or am I missing something? 还是我错过了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.