jQuery Mobile - 不更改哈希值的对话框

发布于 2024-12-10 02:54:09 字数 794 浏览 0 评论 0原文

我有一个搜索对话框,我弹出并填充 jquery 模板。他们做出选择后,我在当前页面上设置一个值。因此,我不需要 hashTags 或类似的东西,我只需要一个可以以编程方式打开和关闭的弹出对话框。我当前正在使用打开对话框

$.mobile.changePage(dialog, { transition: "slide", changeHash: false });

并使用关闭对话框

dialog.dialog('close');

但是,在某些情况下(导航到页面时),关闭对话框会刷新当前页面。

有没有更好的方式与之交互?

更新:

我想我知道发生了什么。因此,出于某种原因,jquery mobile 通常会在 DOM 上加载 2 个页面 - 其中一个页面是不可见的,您可以通过在控制台中运行 $('[data-role=page]') 来验证这一点。一个页面是您当前所在的页面,另一个页面是您最初导航到的页面。不太清楚他们为什么选择这样做,但你已经知道了。

因此,即使对话框已经在 DOM 中,他们也将对话框视为具有不同转换的页面导航。因此,如果您直接进入该页面,然后触发一个对话框,修改当前页面并关闭它就可以正常工作 - 因为原始页面始终加载在 DOM 中。但是,如果您转到另一个页面,而不是导航到触发对话框的页面,然后触发对话框,它会销毁当前页面,以便 DOM 中的页面是初始页面和对话框。在这种情况下,它会完全重新加载该对话框启动页面,并且您永远没有机会进行任何修改。

天啊。如何直接与 jqm 对话框小部件交互?

I have a search dialog that I am popping up and filling with jquery templates. After they make a selection I set a value on the current page. As such I don't need hashTags or anything like that, I just need a pop-up dialog that I can open and close programatically. I am currently opening the dialog with

$.mobile.changePage(dialog, { transition: "slide", changeHash: false });

and closing it with

dialog.dialog('close');

However, in certain cases (when the page is navigated to), closing the dialog refreshes the current page.

Is there a better way to interact with this?

Update:

I think I figured out what is going on. So for some reason, jquery mobile usually keeps 2 pages loaded on the DOM - one of which is invisible, you can verify this by running $('[data-role=page]') in the console. One page is the page you're on, the other is the page that you initially navigated to. Not quite sure why they choose to do that, but there you have it.

So they treat dialogs as a page navigation with a different transition even if the dialog is already in the DOM. Therefore, if you go directly to the page and then trigger a dialog, modifying the current page and closing it works fine - because the original page is always loaded in the DOM. However if you go to another page, than navigate to the page that triggers the dialog, and THEN trigger the dialog it destroys the current page so that the pages in the DOM are the initial one and the dialog. In that case it reloads that dialog-launching page entirely and you never get a chance to make any modifications.

Jeez. How do I interact with the jqm dialog widget directly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终止放荡 2024-12-17 02:54:09

你可以尝试另外两件事。两者都应该有效:

1 套 DomChache
重写 JQM 以保留您在 DOM 中触发对话框的页面怎么样?文档说您可以设置 data-dom-chache 并覆盖从 DOM 清理页面。

如果它仅在您通过 AJAX 加载此页面(而不是直接加载)时发生,您可以使 DOM 保持依赖于具有 data-page-external 的触发页面,分配 DOM-chache="仅当对话框打开时为 true”,并在对话框关闭后再次将其删除。

2 覆盖 JQM
我遇到了与您描述的相同的问题,并让它像这样工作(尽管需要侵入 JQM...):

// inside transitionPages function
if ( !$(toPage).jqmData('internal-page') 
    {fromPage.data( "page" )._trigger( "hide", null, { nextPage: toPage } );}
    }

我的问题是页面更改到某些页面(与对话框相同)导致前一页(对话框从中触发)从 DOM 中删除,所以我有一个空白屏幕(当尝试返回时)。我向页面添加了 data-internal-page="true",这应该保持前一页完整,并在 JQM 中添加了 if 子句。

所以现在 pageHide (和 DOMcleanup)仅在我不打算访问带有 data-internal-page="true" 标签的页面时才会触发 干杯

You can try two other things. Both should work:

1 set DomChache
How about overriding JQM to keep the page your are firing the dialog from in the DOM? The docs say you can set data-dom-chache and override cleaning the page from the DOM.

If it only happens when you load this page in via AJAX (vs. loading it directly) you could make DOM-keeping dependend on your trigger page having data-page-external, assign DOM-chache="true" only when the dialog is openend and remove it again once the dialog is closed.

2 override JQM
I had the same problem you described and got it to work like this (requires hacking into JQM though...):

// inside transitionPages function
if ( !$(toPage).jqmData('internal-page') 
    {fromPage.data( "page" )._trigger( "hide", null, { nextPage: toPage } );}
    }

My problem was that pagechanging to certain pages (same as dialog) caused the preceding page (where the dialog fired from) to be removed from the DOM, so I had a blank screen (when trying to go back). I added data-internal-page="true" to the pages, which should keep the preceding page intact and added the if-clause in JQM.

So now pageHide (and DOMcleanup) only fires, if I'm not going to a page labelled with data-internal-page="true"

Cheers!

梨涡 2024-12-17 02:54:09

我想我也遇到了类似的问题。我想做的是基于某些参数,在加载时弹出一个对话框窗口(该内容位于同一页面上),他们可以关闭该对话框并查看加载的页面。

我可以使用 load 或 pageshow 事件让它在加载时弹出,但是当我单击关闭时,您会返回到历史记录中的上一页,而不是仅仅关闭对话框。

//target your 1st page content, here its id=success
//the modal content is in a page id=dialog and data-role="dialog"

$('#success').live('pageshow',function(){
    window.setTimeout(function(){
        $.mobile.changePage('#dialog','pop',false,false);
    },1);
}

这是一种黑客行为,只允许页面加载击败对话框,因此它会陷入历史记录中。然后,对话框的默认对话框关闭行为将按预期工作。谈论 PITA,如果他们在 JQuery UI 对话框上多花一点时间,事情就会变得容易得多。

I think I was having a similar problem. What I wanted to do was based on certain parameters, pop a dialog window on load (with that content on the same page), which they can close and view the page that loaded.

I could get it to pop on load using load, or the pageshow events, but when I clicked close that sent you back to the previous page in history, instead of just closing the dialog.

//target your 1st page content, here its id=success
//the modal content is in a page id=dialog and data-role="dialog"

$('#success').live('pageshow',function(){
    window.setTimeout(function(){
        $.mobile.changePage('#dialog','pop',false,false);
    },1);
}

Its a hack, and just allows the page load to beat the dialog so it gets stuck in history. Then the default dialog close behavior for the dialog works as expected. Talk about a PITA, if they took a little more for the JQuery UI dialog it would have made things a ton easier.

终弃我 2024-12-17 02:54:09

关于您的问题:您是否看过 Jquery Mobile Actionsheet 插件

如果您真的不知道需要加载一个页面,那应该没问题。

Cagintranet iPad popover 也很有帮助,尽管您必须调整设计以在移动设备上全屏显示。如果您需要 CSS/Jquery 来做到这一点,请告诉我(我在我正在编写的 JQM 插件中使用它)

希望有所帮助。

And regarding your question: Have you looked at Jquery Mobile Actionsheet plugin

If you don't really require a page to be loaded, that should be ok.

Also helpful could be Cagintranet iPad popover, although you have to tweak the design to be fullscreen on mobile devices. If you require CSS/Jquery to do that let me know (I'm using this in a JQM plugin I'm writing)

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文