使用Gridstack从SQL保存的数据构建网格

时间:2018-07-18 10:03:39

标签: c# jquery asp.net-mvc gridstack

我已经开始将GridStack用于一个项目,并且我已经使用以下函数将网格和数据序列化到SQL数据库。

 $('#saveGrid').click(function () {
var items = [];
$('.grid-stack-item.ui-draggable').each(function () {
  var $this = $(this);
  items.push({
    id: $this.attr('id'),
    x: $this.attr('data-gs-x'),
    y: $this.attr('data-gs-y'),
    w: $this.attr('data-gs-width'),
    h: $this.attr('data-gs-height')
  });
});
//console.log(items);

var jsonObject = {
  "DBSettingsID": 1,
  "UserID": 1,
  "LayoutNo": 1,
  "GridLayout": JSON.stringify(items)
};

$.ajax({
  url: "/Dashboard/SaveGridLayout",
  type: "POST",
  data: JSON.stringify(jsonObject),
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  statusCode:

(无需删除其余的邮政编码)

上面保存了一个这样的数组-

[{"id":"jobsToday","x":"8","y":"4","w":"4","h":"4"},{"id":"jobstodayLine","x":"0","y":"4","w":"4","h":"4"},{"id":"dynamicTest","x":"0","y":"0","w":"4","h":"4"},{"id":"outstandingDefects","x":"4","y":"4","w":"4","h":"4"},{"id":"sdTable","x":"4","y":"0","w":"8","h":"4"}]

现在我正在尝试在页面加载时加载它,但是我却不知道如何操作,我使用此功能来获取数组数据

  function loadData() {
$.ajax({
  url: "/Dashboard/LoadGridLayout",
  type: "GET",
  contentType: "application/json;charset=utf-8",
  dataType: "json",
  success: function (data) {
    console.log(data);
    var serialization = [data];
    serialization = GridStackUI.Utils.sort(serialization);
    var grid = $('.grid-stack').data('gridstack');
  },
  error: function (errormessage) {
    alert(errormessage.responseText);
  }
});

我不确定下一步该怎么做,有人问过我一段时间后,我会为我指明正确的方向吗?

0 个答案:

没有答案