简体   繁体   English

在AlloYUI Diagram Builder中更改节点的默认编辑器

[英]Change default editor for node in AlloYUI Diagram Builder

I have to make a diagram editor, so I'm using AlloYUI, I've added a custom node following the answer for this question . 我必须做一个图编辑器,所以我使用的是AlloYUI,我在此问题的答案后面添加了一个自定义节点。

I've successfully set new nodes and retreive it's values via diagramBuilder.toJSON() 我已经成功设置了新节点,并通过diagramBuilder.toJSON()获取了它的值

What I'm trying to do is change the default editor widget for the custom attribute of my custom node, I'd like to change the textbox for date picker widget, but my goal is being able to use any other form elements, like a select, or a set of radio buttons. 我想做的是更改自定义节点的custom属性的默认编辑器小部件,我想更改日期选择器小部件的文本框,但是我的目标是能够使用任何其他表单元素,例如选择,或一组单选按钮。

Toying around with the javascript debugger included in WebStorm, I've found that the default fields have an 'editor' attribute where is defined a "textAreaCellEditor". 玩弄WebStorm中包含的javascript调试器,我发现默认字段具有“ editor”属性,其中定义了“ textAreaCellEditor”。

默认节点属性,如WebStorm调试器中所示

But my custom property doesn't have this attribute, So I'm trying to attach an editor, but I cannot get it to work, I've tried with this: 但是我的自定义属性没有此属性,因此我尝试附加一个编辑器,但无法使其正常工作,我尝试使用以下方法:

Y.DiagramNodeCustom = Y.Component.create({
        NAME: 'diagram-node',

        ATTRS: {
          type: {
            value: 'custom'
          },
          custom_attr: {
            value: 'customAttr'
          }
        },
        EXTENDS: Y.DiagramNodeTask,

        prototype: {
          getPropertyModel: function () {
            var instance = this;

            var model = Y.DiagramNodeTask.superclass.getPropertyModel.apply(
                instance, arguments);

            model.push({
              attributeName: 'customAttr',
              name: 'Custom Attribute',
              editor: Y.Component.create({
                NAME: "DateField",
                EXTENDS: Y.DateCellEditor
              })
            });

            return model;
          },
          SERIALIZABLE_ATTRS: ['description', 'name', 'required', 'type',
            'width', 'height', 'zIndex', 'xy', 'customAttr']
        }

      });
      Y.DiagramBuilder.types['custom'] = Y.DiagramNodeCustom;

I've also tried to change the "model.push" section to: 我还尝试将“ model.push”部分更改为:

model.push({
      attributeName: 'customAttr',
      name: 'Custom Attribute',
      editor: {name: "textCellEditor"}
    });

and to: 并:

model.push({
          attributeName: 'customAttr',
          name: 'Custom Attribute',
          editor: Y.DateCellEditor({
            name: 'DateCellEditor'
          })
        });

But nothing works. 但是什么都行不通。 Do you have any idea how can I change the default editor? 您知道如何更改默认编辑器吗?

Thanks to Robert Frampton, who anwered my question in google groups , the way to do it is: 感谢罗伯特·弗兰普顿(Robert Frampton),他在Google网上论坛中解答了我的问题,解决方法是:

model.push({
   attributeName: 'customAttr',
   name: 'Custom Attribute',

   editor: new Y.DateCellEditor()
});

You have to create a new instance of the Y.DateCellEditor object with adding 'new' before the constructor. 您必须在构造函数之前添加“ new”来创建Y.DateCellEditor对象的新实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM