Backbone JS multiple level navigation example

前端 未结 2 1242
醉酒成梦
醉酒成梦 2021-02-04 22:39

I\'m trying to construct a solid Backbone JS experiment, where I have a local JSON data file which contains my pages (a project I\'m doing has this sort of requirement anyhow).

2条回答
  •  醉梦人生
    2021-02-04 22:52

    Why not just parse out the slug?

    So you can have a single route in the Backbone.Controller that looks like this:

    'pages/:id' : showPage
    

    And then showPage looks like:

    showPage(id) : function(id) {
       parse out the string 'services/details/etc'
       look up the slug data based on that IE pages['services']['details']['etc']
    }
    

    or if the pages actually need to be processed differently, you can setup multiple routes, ever more granular like this:

    'pages/:id' : showPage
    'pages/:id/:nest' : showNestedPage
    'pages/:id/:nest/:more' : showNestedMorePage
    

提交回复
热议问题