您好,目前可以确定,是由于代码中重写了spread.contextMenu.menuView导致的问题。
Designer用的不是普通的MenuView,而是DesignerMenuView,Designer已经对menuView
进行了重写,因此再重写这个类一定会有问题。
解决方法很简单,您在Designer目录下contextMenu/contextMenu.js中找到DesignerMenuView,
加一句声明把DesignerMenuView暴漏出来,代码如下:
- function DesignerMenuView() {
- }
- DesignerMenuView.prototype = new GC.Spread.Sheets.ContextMenu.MenuView();
- DesignerMenuView.prototype.createMenuItemElement = function (menuItemData) {
- var self = this;
- var menuItemView;
- if (menuItemData.name === MENUITEM_NAME_PREFIX + TAB_COLOR) {
- var supMenuItemContainer = GC.Spread.Sheets.ContextMenu.MenuView.prototype.createMenuItemElement.call(self, menuItemData);
- supMenuItemContainer.empty();
- $(supMenuItemContainer[0]).colorpicker(
- {
- valueChanged: function (e, value) {
- if (!value.isSetColorDirectly) {
- $(supMenuItemContainer[0]).data("selectedColor", value);
- } else {
- designer.actions.doAction("setSheetTabColor", designer.wrapper.spread, value.color);
- }
- }
- }
- );
- $(supMenuItemContainer[0]).colorpicker("option", "themeColors", designer.wrapper.getThemeColors());
- supMenuItemContainer.css({ "margin": "0", "padding": "0" });
- supMenuItemContainer.css("background", "white");
- return supMenuItemContainer;
- } else if (menuItemData.name === MENUITEM_NAME_PREFIX + PROTECT_SHEET) {
- var activeSheet = designer.wrapper.spread.getActiveSheet();
- if (activeSheet.options.isProtected) {
- menuItemData.text = contextMenuRes.unprotectsheet;
- } else {
- menuItemData.text = contextMenuRes.protectsheet;
- }
- menuItemView = GC.Spread.Sheets.ContextMenu.MenuView.prototype.createMenuItemElement.call(self, menuItemData);
- return menuItemView;
- } else {
- menuItemView = GC.Spread.Sheets.ContextMenu.MenuView.prototype.createMenuItemElement.call(self, menuItemData);
- return menuItemView;
- }
- };
- DesignerMenuView.prototype.getCommandOptions = function (menuItemData, host, event) {
- if (menuItemData.name === MENUITEM_NAME_PREFIX + TAB_COLOR) {
- return {
- value: $(host).children().data("selectedColor")
- };
- } else if (menuItemData.name === MENUITEM_NAME_PREFIX + FORMAT_CHART) {
- return menuItemData.options;
- }
- };
- spread.contextMenu.menuView = new DesignerMenuView();
- // 在此加一句声明,把DesignerMenuView暴露出来
- GC.Spread.Sheets.Designer.DesignerMenuView = DesignerMenuView;
- designer.spreadActions.initDesignerCommands(spread.commandManager());
- }
复制代码
然后再针对DesignerMenuView进行重写,即可解决这个问题。代码示例如下:
- var spread = GC.Spread.Sheets.findControl("ss");
- function CustomMenuView() { }
- CustomMenuView.prototype = new GC.Spread.Sheets.Designer.DesignerMenuView();
- CustomMenuView.prototype.createMenuItemElement = function (menuItemData) {
- var self = this;
- console.log(menuItemData);
- var menuItemView = GC.Spread.Sheets.Designer.DesignerMenuView.prototype.
- createMenuItemElement.apply(self, arguments);
- return menuItemView;
- };
- spread.contextMenu.menuView = new CustomMenuView();
复制代码 |