如何在面向对象中“选择”上下文菜单项?

时间:2015-12-22 06:37:58

标签: javascript jquery contextmenu handsontable

我是handsontable.js的新手,我遇到了一个小问题。我创建了一个自定义上下文菜单,效果很好。

现在,当我打开一个上下文菜单并应用一个项目,然后再次为同一个单元格打开它时,它将不会显示为已选中。有没有人有想法,如何添加这样的选择(以小刻度/右标/突出显示的形式)?

这是我的代码:

$("#tabledata").handsontable({
        data: datas,
        startRows: 1,
        startCols: 2,
        minRows: 1,
        minCols: 2,
        maxRows: 400,
        maxCols: 200,
        rowHeaders: true,
        colHeaders: false,
        minSpareRows: 1,
        minSpareCols: 1,
        mergeCells: true,
        manualColumnResize: true,
        manualRowResize: true,
        cells: function (row, col, prop) {
            var cellProperties = {};
            cellProperties.renderer = "defaultRenderer"; //uses lookup map
            return cellProperties;
        },
        contextMenu: {

            items: {
                "row_above": {},
                "row_below": {},
                "col_left": {},
                "col_right": {},
                "hsep2": "---------",
                "remove_row": {name:'Remove row(s)'},
                "remove_col": {name:'Remove columns(s)'},
                "hsep3": "---------",
                "alignment" : {},
                "mergeCells" : {},
                "hsep4": "---------",
                "undo": {},
                "redo": {},
                "hsep5": "---------",
                "bold": {"name": "Bold"},
                "italic": {"name": "Italic"},
                "highlighted": {"name": "Highlight"}

            }
        },
        cell: metadata,
        mergeCells: metadata

});

以下是它的外观图像:

enter image description here

有人有想法吗? 欢迎所有答案。

1 个答案:

答案 0 :(得分:0)

我不确定但也许这可以提供帮助 http://docs.handsontable.com/0.20.2/demo-context-menu.html 在这个例子中,他们使用

      items: {
    "row_above": {
      disabled: function () {
        // if first row, disable this option
        return hot3.getSelected()[0] === 0;
      }
    },
    "row_below": {},
    "hsep1": "---------",
    "remove_row": {
      name: 'Remove this row, ok?',
      disabled: function () {
        // if first row, disable this option
        return hot3.getSelected()[0] === 0
      }
    },
    "hsep2": "---------",
    "about": {name: 'About this menu'}
  }
}

描述上下文菜单元素的关键项 并且可以访问所选单元格hot.getSelected() 也许您可以获取单元格的设置以确定是否存在活动属性并添加勾选

相关问题