ember.js v1.0.0-rc.1 - 使用模态插座,如何在关闭模式之外路由出模式? [英] ember.js v1.0.0-rc.1 -- Using a modal outlet, how do I route out of the modal on close?

查看:113
本文介绍了ember.js v1.0.0-rc.1 - 使用模态插座,如何在关闭模式之外路由出模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过应用程序路由渲染所有的模态,但是在我关闭模态后,我无法找出正确的方式返回到之前的状态。



这是基本设置:



我在我的应用程序模板中有一个出口,用于显示模态对话框。



它看起来像:

  {{outlet modal}} 

在我的路线映射中,我已经为单个模态定义了钩子。例如,我的帮助对话框弹出:

  App.HelpRoute = Ember.Route.extend({
renderTemplate :function(controller,model){
this.render({outlet:'modal'});
}
});

现在,我可以通过uri显示我的模态:

  foo.com/#/help 

我有一个钩子来使用jQuery来解除模态:

  $('#modalHelpWindow')。modal('hide') ; 

但这并没有真正的帮助,因为我只是隐藏元素。我需要更新URI被解雇。如果我再次打到同一条路线,模态已经被隐藏了,不显示。



我应该使用什么方法来关闭模态,并路由应用程序回到以前的状态?我应该使用history.back()吗?



请注意,我知道这个SO问题,但解决方案不是首选的ember做事方式,因为以编程方式创建的视图将不会使其控制器正确关联使用Ember路由器v2进入和退出模态的正确方法是什么?

解决方案

p>看起来我可以连接隐藏的处理程序,在我的视图的didInsertElement方法中执行一个history.back()调用,一个:

  didInsertElement:function(){
var $ me = this。$();
$ me.modal({背景:静态});
$ me.on('hidden',function(){
history.back();
});
},


I'm attempting to render all my modals through application routing, but I'm having trouble figuring out the proper way to return to a previous state after I dismiss the modal.

Here's the basic setup:

I have an outlet in my application template which I'm using to display modal dialogs.

It looks something like:

{{ outlet modal }}

In my route mappings, I've defined hooks for the individual modal. For instance, my help dialog pops up with:

App.HelpRoute = Ember.Route.extend({
    renderTemplate: function(controller, model) {
        this.render({ outlet: 'modal' });
    }
});

Right now, I can display my modal through the uri:

   foo.com/#/help

I have a hook to dismiss the modal using jQuery:

$('#modalHelpWindow').modal('hide');

But this doesn't really help, because I'm just hiding the element. I need to update URI on dismissal. If I hit the same route again, the modal is already hidden, and doesn't display.

What methods should I be using to dismiss the modal, and route the application back to its previous state? Should I just be using history.back()?

Note, I am aware of this SO question, but the solution is not the preferred 'ember' way of doing things, as programmatically created views will not have their controllers associated properly What's the right way to enter and exit modal states with Ember router v2?

解决方案

Looks like I can hook up the hidden handler to do a history.back() call in my view's didInsertElement method, a la:

   didInsertElement: function() {
        var $me = this.$();
        $me.modal({backdrop:"static"});
        $me.on('hidden', function() {
            history.back();
        });
    },

这篇关于ember.js v1.0.0-rc.1 - 使用模态插座,如何在关闭模式之外路由出模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆