cordova& jquery:值发送到另一个静态html页面 [英] cordova&jquery:value sent to another static html page

查看:280
本文介绍了cordova& jquery:值发送到另一个静态html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Cordova JQuery 执行ios网络应用程序。我创建了一个3行列表视图的index.html。当该行被点击时,页面将变为另一个page.html。根据点击的行,JS将从服务器请求数据并刷新page.html。
现在我的问题是什么是实现它的最佳实践?我的意思是这是正常的风格做它,因为我新鲜的前端。
目前我在index.html中添加锚点:

I'm doing an ios web app using Cordova and JQuery. I create the index.html which has a 3-row list view. when the row is clicked, the page will change to another page.html. According to the clicked row, the JS will ask data from the server and refresh the page.html. Now My Question is what is the best practice to implement it? I mean which is the regular style to do it as I'm fresh to the front-end. Currently I add the anchor in index.html:

<li><a href="page.html">A Header Bars</a></li>

在page.html中,我如何启动请求获取数据?在page.html中,我写入:

  1. I don't know how to get the clicked row information in page.html
  2. In page.html, how I can start a request to fetch the data? In page.html, I write:

$(document).ready(function()
{
    console.log("test");
    document.write("page test");
})

li>

但不会调用。

谢谢。 $ b

推荐答案

如果你想从一个页面到另一个页面的值有几个选项(相同的规则适用于单个jQM html与多个页面和jQM项目多个html文件):

If you want a value from one page to another you have few options (same rules apply for single jQM html with multiple page's and for jQM project built around multiple html files):

我。在第二个页面上使用pagebeforeshow并通过数据对象检索所有需要的数据。假设你有2个html文件,第一个html有一个idpage1,第二个有一个idpage2),例如:

I. On the second page use pagebeforeshow and retrieve all needed data through a data object. Lets say you have 2 html files, first html has an id "page1" and second one has an id "page2"), example:

$('#page2').live('pagebeforeshow', function (e, data) {
    alert(data.prevPage.find('div[data-role="content"]').attr('id'));
});

II。第二个选项是创建一个将用作数据存储的共享对象:

II. Second option is to create a shared object which will be used as data storage:

var storeObject = {
    someValue : '1',
    anotherValue : '2'
}

最简单的解决方案,但它只会工作,而ajax页面加载是活动。

This is an easiest solution but it will only work while ajax page loading is active.

III。您可以使用changePage传递值:

III. You can pass values with changePage:

$.mobile.changePage('page2.html', { dataUrl : "page2.html?paremeter=123", data : { 'paremeter' : '123' }, reloadPage : true, changeHash : true });

并按如下读取:

$('#page2').live('pagebeforeshow', function (e, data) {
    var paremeter = $(this).data("url").split("?")[1];;
    paremeter = paremeter.replace("paremeter=","");   
    alert(paremeter);
});



更多信息



详细了解此主题,请查看此 文章 strong> 。你会发现几个解决方案的例子。

More info

If you want to learn more about this topic take a look at this article. You will find several solutions with examples.

这篇关于cordova&amp; jquery:值发送到另一个静态html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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