2010-10-28 109 views
0

我該如何使用類似jQuery & PHP來對xml文件中的元素重新排序?用jQuery重新排序XML元素,然後用php保存XML文件

下面的jQuery插件允許交換html錶行或列表項,但我不知道如何通過單擊按鈕將這些更改保存回XML文件。

www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/

www.jqueryui.com/demos/sortable/

這描述了一個功能重新排列/重新排序元素: http://quest4knowledge.wordpress.com/2010/09/04/php-xml-create-add-edit-modify-using-dom-simplexml-xpath/

但是,這隻顯示如何交換兩個元素的位置,而不是多個。 它們是否可以合併以重新排列更長的元素列表?

我試圖避免使用MySQL,PHP只/ jQuery的/ XML ...

<?xml version="1.0" encoding="utf-8"?> 
<gallery> 
    <picture id="0001"> 
    <title>Title One</title> 
    <description>Some text here</description> 
    </picture> 
    <picture id="0002"> 
    <title>Title Two</title> 
    <description>Some more text here</description> 
    </picture> 
    <picture id="0003"> 
    <title>Title Three</title> 
    <description>Some other text here</description> 
    </picture> 
</gallery> 

感謝安迪。使用

回答

0

JS提交重新排序表中的數據jquery.json-2.2.js

$(document).ready(function() { 
    $('#table-1').tableDnD(); 
}); 
function sendData() { 
    data = $('#table-1').tableDnDSerialize(); 
    document.dataform.data.value = $.toJSON(data); 
    return true; 
} 

然後在PHP中接收數據:

$data = json_decode(stripslashes($_POST['data']), true); 
$data = rawurldecode($data); 
$data = explode("&table-1[]=", $data);