本文介绍了将动态生成的列表中的数据从一页传递到另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的jquery移动应用程序中,我有一个动态生成的listview,我想做的是当用户单击列表项时,我想从listitem中的隐藏字段中获取一个值并将该值传递给另一个页面这样我就可以基于该变量值进行查询. (这是多页布局)

Within my jquery mobile app, I have a dynamically generated listview and what I want to do is when the user clicks a list item, I want to get a value from a hidden field within the listitem and pass that value to another page so that I can do a query based on that variable value. (It's multipage layout)

由于我与第一页位于同一DOM中,因此我假定我可以使用普通的旧变量访问数据并传递到另一页.我需要知道的是,如何从动态生成的列表中获取值.任何帮助将不胜感激.

Since I'm in the same DOM as the first page, I assume I can access data using plain old variables and pass to another page. What I need to know is, how do I get a value from dynamically generated list. Any help would be appreciated.

<ul data-role="listview" class="ui-listbox" data-theme="c"  role="listbox" style="margin-top:20px">
    <li data-role="list-divider" role="heading" tabindex="0" class="ui-li ui-li-divider ui-btn ui-bar-b ui-btn-up-undefined">Today's Journey</li>
    <?php foreach ($journeys as $journey) : ?>
    <?php if ($journey['user_type'] == 0): ?>
        <li class="list-item-speaker" data-icon="false">
            <a href="#journeydetails?id=<?php echo $journey['journey_id']; ?>" id="journeyDetailsDriver" data-transition="flip" >
                <div class="list-item-content-speaker" style="float:left">
                    <img src="<?php echo $journey['facebook_image']; ?>" class="thumb-speaker-small" alt="<?php echo $journey['facebook_first_name']." ".$journey['facebook_last_name']; ?>" />
                    <h3 style="padding-left:10px;"><?php echo $journey['from_destination']." - ".$journey['to_destination']; ?></h3>
                    <p style="padding-left:10px"><?php echo $journey['facebook_first_name']." ".$journey['facebook_last_name']; ?></p>
                    <p style="padding-left:10px; padding-top:10px; font-size:0.9em; font-weight:bold"><?php echo $journey['depart_date']; ?></p>
                    //VALUE I NEED FROM HIDDEN FIELD
                    <input type="hidden" name="journeyID" id="journeyID" value="<?php echo $journey['journey_id']; ?>">
                </div>
                <h3 style="float:right; margin-top:45px; color:#189ACB"><?php echo $journey['seats_available']. ' seats'; ?></h3>
            </a>
        </li>
</ul>

推荐答案

您可以使用URL查询标记,也可以将数据保存在Cookie或HTML5本地/会话存储中.

You could use URL query tags, or save the data in a cookie or in HTML5 local/session storage.

要从列表中获取信息,这是一个示例

To get information from a list, here is an example

<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>

var a = [],
    list = document.getElementsByTagName("li");

Array.prototype.forEach.call(list, function(entry) {
    a.push(entry.textContent);
});

console.log(a);

可用于 jsfiddle

这篇关于将动态生成的列表中的数据从一页传递到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 17:12