jQuery Mobile的导航 - 为什么是国家空? [英] jQuery Mobile navigate - Why is the state empty?

查看:136
本文介绍了jQuery Mobile的导航 - 为什么是国家空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 $ mobile.navigate(#测试页,{编号:123})。导航到一个二级页面

I'm using $.mobile.navigate("#test-page", {id:123}) to navigate to a secondary page.

页与页的导航工作正常....但状态是空的!

The navigation from page to page works fine.... but the state is empty!

该文档清楚地表明,国家应包含我需要的时候进行导航的所有信息。

The docs clearly show that the state should contain all information I need when the navigation is performed.

这是在code我使用:

This is the code I'm using:

$(window).on('navigate', function(event, data) {
  console.log("navigated", data);
  console.log(data.state.info);
  console.log(data.state.direction);
  console.log(data.state.url);
  console.log(data.state.hash);
  if (data.state.hash === "test-page") {
    console.log("Test page", data.state.id);
  }
});

不幸的是数据传递为空的:

Unfortunately data is passed as empty:

{
    state:{}
}

的HTML如下:

<div id="test-home" data-role="page">

      <div data-role="header">
          <h1>Test Home</h1>
      </div>
      <div data-role="content">
          <div id="test-btn">
            Click DIV for TEST page
          </div>
      </div>
      <div data-role="footer">
      </div>

  </div>


  <div id="test-page" data-role="page">
     <div data-role="header">
          <h1>Test Page</h1>
     </div>

     <div data-role="content">
        Test page

     </div>
  </div>


希望有人可以提供帮助。谢谢!


Hope that someone can help. Thanks!

推荐答案

$。mobile.navigate 浏览 事件的,用于跟踪URL历史记录,并通过/从URL获取数据。他们的工作与浏览器的导航(前进/后退)。

$.mobile.navigate and navigate event, are used to track URL history and pass/fetch data from URL. They work with browser's navigation (back / forward).

要使用内部动态导航中的Web应用程序通过网页间的数据,使用 $。mobile.changePage

To pass data between pages dynamically within a webapp using internal navigation, use $.mobile.changePage.

资源:

  • $.mobile.navigate()
  • Navigate
  • $.mobile.changePage()

使用下面的code,从页面传递的数据的另一个。

Use the below code to pass data from page to another.

$.mobile.changePage('store.html', {
 dataUrl: "store.html?id=123",
 data: {
    'id': '123'
 },
 reloadPage: true // force page to reload
});

要检索的数据

$('.selector').on('pagebeforeshow', function () {
 var values = $(this).data("url").split("?")[1];
 id = values.replace("id=", "");
 console.log(id);
});

这篇关于jQuery Mobile的导航 - 为什么是国家空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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