如何保存 Malhar Angular 小部件上的样式更改?

问题描述 投票:0回答:1

我已经在我的 AngularJS 应用程序中安装了 malhar-angular-dashboard 模块。 我配置了一个带有显式保存的布局。 问题是我不知道如何保存小部件样式更改。 关闭模型设置窗口后,我想更改并保存 contentStyle 的背景(背景:红色)

JavaScript

'use strict';

angular.module('widget-area')

.factory('widgetDefinitions', function() {
return [
  {
    name: 'widgetComments', // attr required
    title:' ',
    templateUrl: 'views/dashboards/widget-area/sarciniPrimiteComentarii.html',
    settingsModalOptions:{
      templateUrl: 'views/dashboards/widget-area/modalSettings/widgetCommentsModalTmpl.html',
      controller:'widgetCommentsCtrl'
    },
    onSettingsClose: function(resultFromModal, widgetModel, dashboardScope) {
      // do something to update widgetModel, like the default implementation:
      //jQuery.extend(true, widget, result);
      widgetModel.contentStyle = {
        background:'red'
      };
      // something here to save the state
    },
    size: {
      width: '100%',
      height: '250px'
    }
  },
  {
    name: 'widgetInfoSarciniPrimite', // attr required
    title:' ',
    templateUrl: 'views/dashboards/widget-area/infoSarciniPrimite.html'
  },
  {
    name: 'widgetInfoColaborare', // attr required
    title:' ',
    templateUrl: 'views/dashboards/widget-area/infoColaborariSarciniPrimite.html'
  },
  {
    name:'widgetTest',
    title:' titleTest ',
    template:'<div><h2>Widget {{widget.title}}</h2></div>'
  }
];
})
.factory('defaultWidgets', function() {
return [
  {name: 'widgetComments'}, //attr required
  {name: 'widgetInfoSarciniPrimite'},
  {name: 'widgetInfoColaborare'},
  {name: 'widgetTest'}
];
})
.controller('widgetCtrl',['$scope','$interval', '$window','$translate','widgetDefinitions','defaultWidgets',
function($scope,$interval,$window,$translate,widgetDefinitions,defaultWidgets){

  $scope.layoutOptions = { // layout with explicit save
    storageId: 'demo-layouts-explicit-save',
    storage: localStorage,
    storageHash: 'fs4df4d51',
    widgetDefinitions: widgetDefinitions,
    defaultWidgets: defaultWidgets,
    explicitSave: true,
    defaultLayouts: [
      { title: 'Layout 1', active: true , defaultWidgets: defaultWidgets },
      { title: 'Layout 2', active: false, defaultWidgets: defaultWidgets },
      { title: 'Layout 3', active: false, defaultWidgets: defaultWidgets }
    ]
  };
}]);
javascript angularjs angularjs-module
1个回答
2
投票

必须从我的Widget定义对象覆盖serialize(Function)并包含我想要序列化的属性:contentStyle

此函数将确定如何保存小部件的状态

.factory('widgetDefinitions',function(){
   return [
     {
        {
          name: 'widgetInfoSarciniPrimite', // attr required
          title:' ',
          templateUrl: 'views/dashboards/widget-area/infoSarciniPrimite.html',
          serialize: function() {
             return _.pick(this, ['title', 'name', 'style', 'size', 'contentStyle', 'dataModelOptions', 'attrs', 'storageHash']);
          }
         }
     }
   ];
})
© www.soinside.com 2019 - 2024. All rights reserved.