网格堆栈序列化功能不返回

时间:2015-09-30 11:48:54

标签: javascript jquery ajax

我目前正在尝试序列化网格堆栈容器中的所有网格,我可以看到元素属性中保存的值,但它似乎不想正确返回对象。当我执行我的ajax POST请求时,未分配窗口小部件数据,因为我的函数返回undefined。

window.onbeforeunload = function (e) {
        //store grid into a variable to be manipulated
        this.grid = $('.grid-stack').data('gridstack');

        //we create a saveGrid method to save attributes to the database
        this.save_grid = function () {
            this.serialized_data = _.map($('.grid-stack > .grid-stack-item:visible'), function (el) {
                el = $(el);
                var gridID = el.find('.grid-stack-item-content.ui-draggable-handle').first().attr('id');
                var node = el.data('_gridstack_node');
                return {
                    id: gridID,
                    x: node.x,
                    y: node.y,
                    width: node.width,
                    height: node.height
                };
            }, this);
        };

        $.ajax({
            url: 'Dashboard/EditWidgets/',
            type: 'POST',
            data: {
                widget: this.save_grid
            },
            success: function (dataset) {
            },
            failure: function (xhr, error) {
                console.log(xhr)
                console.log(error)
            },
            cache: false
        })
    };

0 个答案:

没有答案