Select the nodes whose attribute (array type) contains a specific value using cytoscape.js

I am currently browsing a network where the nodes have a type list attribute, for example:

{"data": {"name": "b", "go": ["c", "d", "f"], "id": "n0"}, "group": "nodes"},
{"data": {"name": "a", "go": ["a", "b", "c"], "id": "n1"}, "group": "nodes"},
{"data": {"target": "n0", "source": "n1", "id": "e1"}, "group": "edges"}

Is it possible, using cytoscape.js, to select all nodes whose list attribute ('go' in the example) contains a specific value?

Sort of:

cy.elements('node[go.contains("b")]')

which node n1 will select ...

Thank you very much in advance

+4
source share
1 answer

Alternative: If you do not need to use selectors, you can use the filter function instead and save the attribute as an array: cy.elements().filter(function(){ return this.data('go').indexOf('foo') >= 0; })

, , , , . , , .

, . : , go: { foo: true, bar: true }. undefined , , .

, node[go\\.foo] ( node[?go\\.foo], ). (, node.data('go.foo') ? 'has it' : 'does not').

+3

All Articles