【问题标题】:Backbone route with unlimited optional parameters具有无限可选参数的骨干路由
【发布时间】:2014-09-18 01:24:47
【问题描述】:

在我的应用中,我有两个重要的模型:ContentCollection 和 ContentItem。

每个 ContentCollection 都有许多 ContentCollections 和 ContentItem。您可以将 ContentCollections 视为文件夹,将 ContentItems 视为文件。所以,这种结构需要是可能的:

-  ContentCollection
   \- ContentCollection
      \- ContentCollection
         \- ContentCollection
            \- Item
            \- Item
      \- ContentCollection
         \- Item
-  ContentCollection
   \- Item
   \- Item
-  Item
-  Item

我想为 ContentCollections 和 ContentItems 创建显示路线。

/home/collections/{id}

还有……

/home/items/{id}

还有……

/home/collections/{id}/collections/{id}/collections/{id}

还有……

/home/collections/{id}/collections/{id}/collections/{id}/items/{id}

等等。

有没有一种简单的方法可以优雅地处理主干路由中的这种嵌套?

【问题讨论】:

    标签: javascript html backbone.js backbone-routing


    【解决方案1】:

    你需要一个包罗万象的路线,它可以匹配任何东西......

    var MyRouter = Backbone.Router.extend({
      '*collection': 'showCollection'
    });
    

    然后在你的动作中进行一点解析:

    Controller = {
      showCollection: function (query) {
        segments = query.split('/')
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      相关资源
      最近更新 更多