Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Svg JointjS:如何获取给定元素的属性?_Svg_Jointjs - Fatal编程技术网

Svg JointjS:如何获取给定元素的属性?

Svg JointjS:如何获取给定元素的属性?,svg,jointjs,Svg,Jointjs,我有一个元素定义如下: var m1 = new joint.shapes.devs.Model({ position: { x: 100, y: 50 }, size: { width: 190, height: 50 }, inPorts: ['in'], outPorts: ['out'], attrs: { '.label': { text: 'Model','ref-x': .4, 'ref-y': .25 ,fill: '#fe

我有一个元素定义如下:

var m1 = new joint.shapes.devs.Model({
    position: { x: 100, y: 50 },
    size: { width: 190, height: 50 },
    inPorts: ['in'],
    outPorts: ['out'],
    attrs: {
        '.label': { text: 'Model','ref-x': .4, 'ref-y': .25 ,fill: '#fefefe',
            'font-size': 14,
            'font-weight': 'bold', 
            'font-variant': 'small-caps' },
        rect: { fill: '#fefefe'},
        '.inPorts circle': { r:5 ,fill: '#16A085' ,magnet: 'passive', type: 'input'},
        '.outPorts circle': { r:5, fill: '#E74C3C',magnet: 'passive',type: 'output' },
    }
问题是如何获取“.label”属性? 例如,我需要得到文本“Model”,我应该怎么做? 如果我想获得'rect'的'fill'属性,我可以简单地使用m1.get('attrs').rect.fill

但是我不知道如何获取“.label”attr。

使用
attr()
方法设置属性并将其返回:

m1.attr('.label/text') // 'Model'
m1.attr('.label/text', 'New Model')
m1.attr('.label/text') // 'New Model'
“/”
是嵌套的
attrs
对象的路径分隔符。

使用
attr()
方法设置属性并将其取回:

m1.attr('.label/text') // 'Model'
m1.attr('.label/text', 'New Model')
m1.attr('.label/text') // 'New Model'
'/'
是嵌套的
attrs
对象的路径分隔符。

var rootnode=new joint.shapes.basic.Circle({
位置:{x:20,y:220},
尺寸:{宽:60,高:30},
属性:{
text:{text:'父'},
圆圈:{fill:'yellow',hasChildren:false}
},
姓名:“家长”
});
addCell(rootnode);
var rootnode=new joint.shapes.basic.Circle({
位置:{x:20,y:220},
尺寸:{宽:60,高:30},
属性:{
text:{text:'父'},
圆圈:{fill:'yellow',hasChildren:false}
},
姓名:“家长”
});
addCell(rootnode);