SetPaintStyle之后获取jsPlumb线颜色 [英] Get jsPlumb Line Color After SetPaintStyle
本文介绍了SetPaintStyle之后获取jsPlumb线颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经成功地使用jsPlumb创建了一行.下面是代码:
I had sucessfully created a line using jsPlumb. Below is the code:
myid_create_line_instance(0, '1px', '#00000');
//A function that creates line instance.
function myid_create_line_instance(id, width, color){
jsPlumb_instance[id] = jsPlumb.getInstance();
var id1 = 'myid_templates_editor_line_' + id + '_pair_1';
var id2 = 'myid_templates_editor_line_' + id + '_pair_2';
var endpointOptions = {
anchor:'BottomCenter',
maxConnections:1,
endpoint:['Rectangle',{width:'1px', height:'1px' }],
connectorStyle:{lineWidth:width,strokeStyle:color},
connector:['Straight'],
};
div1Endpoint = jsPlumb_instance[id].addEndpoint(id1, endpointOptions);
div2Endpoint = jsPlumb_instance[id].addEndpoint(id2, endpointOptions);
jsPlumb_instance[id].connect({
source:div1Endpoint,
target:div2Endpoint,
});
jsPlumb_instance[id].draggable(id1);
jsPlumb_instance[id].draggable(id2);
}
我通过下面的代码编辑了线条的颜色和宽度.
I edited the color and width of the line by the code below.
//The width and color values are from the users input.
width = '5px';
color = '#ff8080';
jsPlumb_instance[0].select().setPaintStyle({lineWidth: width, strokeStyle:color});
我想将所选的线条的宽度和颜色保存到数据库中,所以我使用下面的代码:
I want to save the selected width and color of the line to the database, so I use the code below:
console.log(myid_get_line_color(0));
console.log(myid_get_line_width(id));
//A function that gets the line color base on it's id.
function myid_get_line_color(id){
var connections = jsPlumb_instance[id].getConnections();
return connections[0]['endpoints'][0]['connectorStyle']['strokeStyle'];
}
//A function that gets the line width base on it's id.
function myid_get_line_width(id){
var connections = jsPlumb_instance[id].getConnections();
return connections[0]['endpoints'][0]['connectorStyle']['lineWidth'];
}
控制台返回1
和#00000
,这是不正确的.它正在输出先前的值.我该怎么解决?
The console returns 1
and #00000
, which is not right. It was outputting the previous values. How am I gonna fix it?
推荐答案
I fix my own problem with the help of a post in stackoverflow. Instead of using setPaintStyle
, I used getPaintStyle
.
jsPlumb_instance[id].select().getPaintStyle()[0][0].strokeStyle = color;
jsPlumb_instance[id].select().getPaintStyle()[0][0].lineWidth = width + 'px';
这篇关于SetPaintStyle之后获取jsPlumb线颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文