JQTouch:在“视图”之间传递数据

发布于 2024-11-07 19:28:04 字数 303 浏览 0 评论 0原文

嗨,我今天一直在玩 jqtouch,我只是想知道如何管理数据。

我尝试环顾四周,但没有看到太多文档。

如果我有一个产品的链接列表?我点击一个可以导航到产品“视图”。如何像传递 $_GET 变量一样传递变量来选择该产品?

或者即使我将链接的 id 设置为记录的 id 并使用 JS 获取 ID 并以某种方式将其传递到下一个视图?

任何对此的帮助将不胜感激!

注意:我还想将它与离线扩展一起使用,所以我不确定 get ajax 是否有效

问候,

Billy

Hi I have been playing around with jqtouch today and I'm just wondering how to manage data.

I tried looking around but couldn't see much documentation.

If I had a list of links for say products? And I click on one i can navigate to the product 'view'. How to I pass variables like you would a $_GET variable to select THAT product?

Or even if I set the id of the link to the id of the record and use JS to grab the ID and somehow pass it to the next view?

Any help with this would be most appreciated!

NOTE: I also want to use it with the offline extension so I'm not sure get ajax would work

Regards,

Billy

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

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

发布评论

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

评论(2

江湖彼岸 2024-11-14 19:28:04

您可以使用数据对象的referrer 属性。该链接将如下所示:

<a href="#view" id="1">Product #1</a>

其中 HTML ID 与产品 ID 相对应。然后在“pageAnimationEnd”事件中,您可以检索产品详细信息,如下所示:

$('#view').bind('pageAnimationEnd', function (e, info) {
  // get the id of the calling href
  var id = $(this).data('referrer')[0].id;

  $.getJSON('/products/' + id, function (data) {
    // do something with the data
  });
});

You can use the referrer property for the data object. The link would look like:

<a href="#view" id="1">Product #1</a>

where the HTML ID would correspond to the product ID. Then in the "pageAnimationEnd" event you can retrieve the product details like this:

$('#view').bind('pageAnimationEnd', function (e, info) {
  // get the id of the calling href
  var id = $(this).data('referrer')[0].id;

  $.getJSON('/products/' + id, function (data) {
    // do something with the data
  });
});
九局 2024-11-14 19:28:04

您可以查看演示来了解它是如何进行表单提交的,即AJAX > POST 表单示例。本质上,您创建一个表单和一个 jQT 样式的提交按钮:

<form id="ajax_demo" action="ajax_demo.php" method="POST" class="form">
  ...
  <a class="submit whiteButton" href="#">Submit</a>
</form>

然后在您的接收页面(即 ajax_demo.php)中,您可以访问表单字段,例如 PHP 的 $_GET 或 JavaScript 的 location.search

另一种方法是使用 jQuery 将数据存储在 DOM 中:

// in global level
$('body').data('ajax_demo', "some data for the page");

// in page/view level
$('#ajax_demo').data('key', 'value');

You could look at the demo to see how it does form submission, i.e. AJAX > POST Form Example. Essentially, you create a form and a jQT-style submit button:

<form id="ajax_demo" action="ajax_demo.php" method="POST" class="form">
  ...
  <a class="submit whiteButton" href="#">Submit</a>
</form>

Then in your receiving page (i.e. ajax_demo.php), you can access the form fields, e.g. PHP's $_GET or JavaScript's location.search.

Another way is to store the data in the DOM with jQuery:

// in global level
$('body').data('ajax_demo', "some data for the page");

// in page/view level
$('#ajax_demo').data('key', 'value');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文