代码之家  ›  专栏  ›  技术社区  ›  Konrad Höffner

如何否定Cytoscape.js中的类选择器?

  •  1
  • Konrad Höffner  · 技术社区  · 7 年前

    根据 http://js.cytoscape.org/#selectors/data , " [^name] 如果未定义指定的数据属性,则匹配元素”,但是类不是数据属性,并且 ^.myclass 不起作用,也不起作用 :not(.myclass) .

    错误是 The selector :not(.myclass) is invalid

    2 回复  |  直到 7 年前
        1
  •  1
  •   Stephan T.    7 年前

    如果要获取负类选择器,可以执行以下操作:

    cy.elements().not(cy.$('.yourClass'));
    
    // in more detail
    var allElements = cy.elements(); // get all elements
    var negators = cy.$('.yourClass');  // get all elements with the class to negate
    var result = allElements.not(negators); // gets the difference between the two collections
    
        2
  •  1
  •   user3140972    7 年前

    如果您真的只想通过使用选择器来实现这一点,那么您可以向每个具有 myclass (这可以在添加类时完成),然后使用 [^myclass]