Gridster angularjs获得序列化数据

时间:2015-03-23 09:25:14

标签: javascript angularjs gridster

在gridster的角度版本中如何获取序列化数据。基本上我需要修改每个gridster项的位置和大小。是否有任何规定来实现它?在jquery版本的gridster中,它提供了序列化的选项。

1 个答案:

答案 0 :(得分:0)

我认为最好的方法是在ng-click创建按钮功能:

//Used to save the dashboard to BOTH local storage and PENN database
//Local storage will attempt to be loaded first. However, if local storage is not there
//then we will load the dashboard from the database
$scope.serialize = function() {

    $scope.dashboardJSON = angular.toJson($scope.standardItems);

    localStorageService.set("DashboardInfo", $scope.dashboardJSON);

    //Send HTTP request 'POST' to saveDashboard function in Rails controller
    $http({
        method: 'POST',
        url: 'saveDashboard',
        data: {'dashboardInfo': $scope.dashboardJSON },
        headers: {'Content-Type': 'application/json' }
        }).success(function(data, status, headers, config)
        {
            //Let user know that their dashboard was saved with this success flash
            $scope.successSavingDashboardToDBAlert();
        }).error(function(data, status, headers, config)
        {
            //Let the user know the dashboard could not be saved with this error flash
            $scope.errorSavingDashboardToDBAlert();
        }); 

};

$scope.dashboardJSON然后会是这样的:

[
  {
    "name":           "Speedometer",
    "sizeX":          2,
    "sizeY":          3,
    "content":        "<speeometer></speedometer>",
    "widgetSettings": {"id":2},
    "market":         "Medical",
    "duration":       "Monthly",
    "total":          0,
    "showTarget":     true,
    "row":            0,
    "col":            0
  }
]