2010-10-28 107 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);