问题
I am using following json content for specifying the size of each node:
"data": {
"id": "Name",
"name": "NameID",
"faveColor": "#86B342",
"size": 120
}
Once the graph is generated, I wish to increment the size of all nodes by a particular value (which comes from user input).
Given the fact that
'data(size)' + value
isn't a legit operation, can anyone suggest an apt way to achieve it?
Thanks
回答1:
You are trying to add a int with string which won't seem to work. Instead try to get the property value and then add the input value to it.
You can edit the data value by passing a second argument to nodes().data('element', 'value')
Your code would look something like this:
cy.nodes().forEach(function(node){
node.data('size', parseInt(node.data('size')) + 10);
console.log(node.data('size'))
});
来源:https://stackoverflow.com/questions/41995471/incrementing-the-size-of-nodes-in-cytoscape-js-by-a-specific-value