【问题标题】:Ember. Making modal view that has its own route余烬。制作有自己路线的模态视图
【发布时间】:2013-09-30 06:30:44
【问题描述】:

我想制作一个可以通过自己的路线访问的模态视图。

问题是——我想在我的应用程序的其他状态/视图/路由之上显示这个视图,这些状态/视图/路由内部计算了大数据。

我认为我可以使用嵌套路由来做到这一点。如果我们运行过渡到子路由,则不会重新计算任何内容,只是子显示 - 非常好。

但在实践中,当我尝试为我的一些资源添加子路由时。我遇到了this question 中描述的问题。所以,嵌套路由不是解决它的办法。

什么是解决方案?有什么想法吗?

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    如果它必须在自己的路由中,更合适的方法是有一个单独的路由,您将“先前路由”上下文传递给它以避免发生路由序列化冲突。如果您愿意没有单独的路线,您可以只在新的插座中呈现“模态”视图,而不是将上下文“面包屑”传递到模态路线的开销。

    【讨论】:

    • 无论如何我必须将模态渲染到新的出口。我按照您建议的类似方式制作了它,但略有不同。看我的回答。
    【解决方案2】:

    我的解决方案在这里。 (事实是它的嵌套路由有一些作弊)

    1) 模态转到“模态”出口

    2) 我们有不同名称但路径部分相同的模式路径。

    this.resource('category', { path: '/category/:category_id' }, function () {
        /* Different names for the same modal route */
        this.resource('modal1', { path: 'card/:card_id' });
    });
    
    // url - semantic/books/card/id99
    this.resource('semantic', { path: '/semantic/:semantic_id' }, function () {
        /* Different names for the same modal route */
        this.resource('modal2', { path: 'card/:card_id' });
    });
    

    3) 在执行 transitionTo 时,我们必须为父路由传递上下文

    var curPath = this.controllerFor("application").currentPath;
    
    if (/^category/g.test(curPath))
        this.transitionToRoute('modal1', { category_id: cat_id, card_id: card_id ) });
    else if (/^semantic/g.test(curPath)) 
        this.transitionToRoute('modal2', { semantic_id: sem_id, card_id: card_id ) });              
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多