当我将此函数返回的对象发布到 ajax 帖子中时,为什么会出现“ Uncaught TypeError: Illegal invocation ”:
base.serialize = function()
{
var data
, depth = 0;
step = function(level, depth)
{
var array = [ ]
, items = level.children("li");
items.each(function()
{
var li = $(this)
, item = $.extend({}, li.data())
, sub = li.children("ol");
if (sub.length)
{
item.children = step(sub, depth + 1);
}
array.push(item);
});
return array;
}
data = step(base.$el, depth);
return data;
};
我要做的是将带有数据值的 HTML 树转换为数组,以将排序顺序保存到数据库:
/*
* ------------------------------------------------------
* Liveflex Treeview
* ------------------------------------------------------
*/
var tree = $(".dd-list").liveflex_treeview({
handle : 'div.dd-handle'
, opencollapse : '.opencollapse'
, itemMoved : function(e)
{
var sort_array = e.serialize();
// Save order
$.post('/url_fetch/sort_posts', { 'sort_array' : sort_array }, function(data)
{
console.log('Data:' + data);
});
}
});