Jqmobile中的数据转换和数据ajax [英] Data-transition and data-ajax together in Jqmobile

查看:114
本文介绍了Jqmobile中的数据转换和数据ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Jqmobile代码中,我尝试通过将data-transition="slide"用作锚链接来转换页面. 问题是链接的页面具有由我自己编写的自定义jquery ... 当我用data-transition ="slide"和href击中锚点时,它肯定会过渡,但是链接的页面自定义jquery脚本无法运行... 我尝试使用data-ajax-"false",但是在这种情况下运行自定义脚本,但没有运行data-transition="slide" ... 我要两个一起跑...可以吗... ??

In my Jqmobile code, i am trying to transit pages by applying data-transition="slide" for anchor links.. The Problem is that the linked pages have custom jquery coded by myself... When i hit an anchor with data-transition="slide" and href then it surely transit but the linked page custom jquery scripts do not run... I tried using data-ajax-"false" but in this case custom script runs but not data-transition="slide"... I want both together to run... Can it be possible...??

这是简单的自定义,在这里我是显示/隐藏输入框.

Here is the simple custom, in this i am show/hiding input boxes..

<script type="text/javascript">
$(document).bind("pageinit", function(){
      $('#near_index').hide();
      $('#find').click(function() {
             $('#near_index').show();       
      });
    });
</script>

这是HTML,

<a href="category.html" data-transition="slide" data-ajax-"false"><img src="images/23-bird.png" alt="Category 2" class="ui-li-icon iconSmall">Category 2</a>

推荐答案

pageinit 用于插件初始化-请参见

pageinit is for plugin intialization - see here.

因此,此事件仅在JQM首次加载时触发一次.在您的页面"(DOM)初始化之后.您加载的任何其他页面都将被拉入DOM,但不会触发另一个 pageinit .

So this event will only fire once when JQM first loads. After your "page" (DOM) is initialized. Any other pages you load will be pulled into the DOM, but will not trigger another pageinit.

只需使用任何其他可用事件(上面的链接),例如 prebeforeshow pageshow .这些将在加载到DOM中的每个页面时触发.只需将console.log("HELLO")放在事件处理程序中,看看它是否会触发.

Just use any of the other available events (link above), such as pagebeforeshow or pageshow. These will fire with every page that is loaded into the DOM. Just put a console.log("HELLO") inside the event handler and see if it fires.

编辑过渡:
您不能设置data-ajax ="false"并进行转换(从A页到B页),因为这种转换是使用AJAX将新页面加载到DOM中而与常规链接(data-ajax)相对应的结果="false")删除旧DOM并加载新页面(新DOM).

EDIT Transitions:
You cannot set data-ajax="false" and have a transition (slide from page A to page B), because the transition is the result of using AJAX to load the new page INTO the DOM vs. a regular link (data-ajax="false") dropping the old DOM and loading the new page (new DOM).

JQM的概念是始终保留在相同的页面"中,而仅通过Ajax加载/加载新页面.这样便可以进行过渡(加载新页面,将其放置在旧页面旁边,然后滑动).

The concept of JQM is to always stay in the SAME "Page" and just load in/out new pages via Ajax. That's how you can do transitions (load a new page, position it next to the old one and then slide).

这也可能是您的自定义代码未触发的原因,因为如果您说 data-ajax ="false" ,则是告诉JQM我在这里做完了",并加载新的页面.

This may also be the reason your custom code is not firing, because if you say data-ajax="false" you are telling JQM "I'm done here", and load a new page.

如果不需要data-ajax ="false",请忽略它.

If you don't need data-ajax="false", leave it out.

这篇关于Jqmobile中的数据转换和数据ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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