【问题标题】:im trying to use diagram.highlightCollection in gojs to highlight nodes that fail certain condition我试图在 gojs 中使用 diagram.highlightCollection 来突出显示不符合特定条件的节点
【发布时间】:2020-02-05 13:35:41
【问题描述】:

我有节点(键)的 id,我想突出显示这些节点,对于空节点,相同的条件可以正常工作。例如:

    checkEmptyNodes() {
           const emptyNodes = [];
           const diagDetails =  this.myserv.getDiagramData();
           if (!!diagDetails.nodeDataArray) {
           diagram.startTransaction('checking empty nodes');
           diagram.nodes.each(n => {
                       if (!n.part.data.answer) {
                           emptyNodes.push(n);
                   }
           });
           diagram.highlightCollection(emptyNodes);
           console.log(emptyNodes);
          }   else {
           // data.answer = [];
          }
           diagram.commitTransaction('checking empty nodes');
           return emptyNodes;
         }  

上面的代码有效,但我有一个类似的代码,它没有给出任何错误,但节点没有被突出显示

          changeNodeColor(broken){
            const brokenNodes = [];
            diagram.nodes.each(n => {
                     if (broken.includes(n.Zd.key)) {
                     diagram.startTransaction('checking hanging nodes');
                    brokenNodes.push(n);
                         }
                     });
                 console.log("data here nk data");
                 console.log(brokenNodes);
                 diagram.highlightCollection(brokenNodes);
                 diagram.commitTransaction('checking hanging nodes');
                 return brokenNodes;
              }

我真的不知道前一个工作是如何工作的,以及为什么第二个工作不工作。 任何 gojs 专家。

【问题讨论】:

    标签: javascript gojs


    【解决方案1】:

    我已经在https://forum.nwoods.com/t/i-want-to-color-node-based-on-certain-condition/13169 回答了这个问题,为了完整起见,这是我的回答:

    不要使用Zd。这是一个缩小的属性名称,并且在文档和本论坛中反复声明您不应该使用这些内部名称。仅使用记录在案的 API 属性和方法名称:https://gojs.net/api

    为什么要在迭代或循环中调用 startTransaction?你以前没有。应该始终对 startTransactioncommitTransaction(或 rollbackTransaction)进行一对调用。这些配对通常是连续的,但它们可能会嵌套。

    【讨论】:

      猜你喜欢
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 2016-11-25
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      相关资源
      最近更新 更多