简体   繁体   中英

Pass data from a dynamically generated list from one page to another

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)

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>

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);

Available on jsfiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM