dsm1998 2012-04-11 12:19
浏览 55

新手到Javascript,jQuery和Ajax

OK - I've figured out how to use a jquery drag-drop sortable ui. I've also figured out how to populate the jquery list with time data from my table. But... I'm up against another brick wall.

Following is the script for test.php

<?php
session_start();
// include database connection file, if connection doesn't work the include file will throw an error message
include '../schedule/include/db_connect.php';

    $date1 = "10/01/2012";
        echo $date1;

// strtotime() will convert nearly any date format into a timestamp which can be used to build a date with the date() function.
$timestamp = strtotime($date1);
$start_date = date("Y-m-d", $timestamp);

$result="SELECT DATE_FORMAT(List_Dates.DB_Date, '%m/%d/%Y') as newdate, DATE_FORMAT(List_Time.TFM_Time,'%h:%i %p') as newtime
FROM List_Dates, List_Time
WHERE DATE(DATE_FORMAT(List_Dates.DB_Date,'%Y-%m-%d')) LIKE '" . $start_date . "%'
ORDER BY List_Time.TFM_Time";

$answer = mysql_query($result);

?>
<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="utf-8">
        <title>jQuery UI Sortable - Connect lists</title>
        <link rel="stylesheet" type="text/css" href="../schedule/include/formats.css"/>
        <link rel="stylesheet" href="../jquery/themes/custom-theme/jquery.ui.all.css">
        <script src="../jquery/jquery-1.7.1.js"></script>
        <script src="../jquery/ui/jquery.ui.core.js"></script>
        <script src="../jquery/ui/jquery.ui.widget.js"></script>

        <script src="../jquery/ui/jquery.ui.mouse.js"></script>
        <script src="../jquery/ui/jquery.ui.sortable.js"></script>
        <script src="../jquery/ui/jquery.ui.selectable.js"></script>
        <style>
        #sortable1, #sortable2 { list-style-type: none; margin: 0; padding: 0 0 2.5em; float: left; margin-right: 10px; }
        #sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 120px; }
        </style>
        <script>
        $(function() {
                $( "#sortable1, #sortable2" ).sortable({
                        connectWith: ".connectedSortable"
                }).disableSelection();
        });
        </script>
</head>
<body>

<div>
<ul name="timelist" id="sortable1" class="connectedSortable">
<?php
while($row = mysql_fetch_array($answer))
{
        echo "<li class='ui-state-default'>". $row['newtime'] ."</li>";
}
?>
</ul>

<ul name="blocklist" id="sortable2" class="connectedSortable">
        <li id="blocked" type="date" class="ui-state-highlight"></li>
</ul>
</div>

</body>
</html>

As I mentioned earlier, the script is successfully populating a sortable drag-drop list with times from my database. I can drag and drop one time from the left side timelist to the right side blocklist. Now I need to extract an array from the blocklist. I found the following:

<script>
$('ul#myList li').each(function(){
var number = $(this).find('span:first-child').text();
var fruit = $(this).find('span:first-last').text();
});
</script>

For my application it makes sense to change the syntax as follows:

<script>
$('ul#sortable2 li').each(function(){
var btime = $(this).find('span:first-child').text();
});
</script>

But... I can't figure out how to succesfully use it and echo the results. Everything I've tried results in failure. Any advice is welcome.

Thanks Much - Pavilion

  • 写回答

1条回答 默认 最新

  • douan4347 2012-04-11 12:40
    关注

    Check the jQuery UI documentation there is a method called toArray which you can call on your sortable element to get, well, an array.

    http://jqueryui.com/demos/sortable/#method-toArray

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘