Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G6 数据模型自定义字段 #10

Closed
MagnificentSun opened this issue Mar 19, 2020 · 1 comment
Closed

G6 数据模型自定义字段 #10

MagnificentSun opened this issue Mar 19, 2020 · 1 comment

Comments

@MagnificentSun
Copy link

// 注册模型卡片基类
Flow.registerNode('model-card', {
    draw(item) {
        const group = item.getGraphicGroup();
        const model = item.getModel();
        model.myData; // 定义自己的变量
        const width = 184;
        const height = 40;
        const x = -width / 2;
        const y = -height / 2;
        const borderRadius = 4;
        const keyShape = group.addShape('rect', {
            attrs: {
                x,
                y,
                width,
                height,
                radius: borderRadius,
                fill: 'white',
                stroke: '#CED4D9'
            }
        });
        
        // 自定义 myData
        group.addShape('text', {
            attrs: {
                text: myData,
                x: x + 52,
                y: y + 13,
                textAlign: 'start',
                textBaseline: 'top',
                fill: 'rgba(0,0,0,0.65)'
            }
        });
 componentData: {
            get() {
                return this.selectedModel.myData; // selectedModel 在page.on 点击node 获取的 model
            },
            set(value) {
                this.updateGraph('myData', value); // tempSelectedModel 组件定义的变量
                this.tempSelectedModel = null;
            }
        },
// 组件引用 componentData
<el-form label-width="60px">
                                    <el-form-item label="自定义:">
                                        <el-input v-model="componentData"/>
                                    </el-form-item>
                                </el-form>
// 组件绑定的 componentData 能赋值但是不能赋值在 model.componentData
// 但是很神奇 label 就可以赋值到 model.label 
// 场景就是 自定义数据 能赋值 接口拿回的数据 能回显到节点 刚刚不小心把上条删了 跪求大佬指点一二 下周提测卡住了
@guozhaolong
Copy link
Owner

不好意思刚看到,昨晚家里进黄鼠狼了,一宿没咋睡...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants