【问题标题】:Boolean in array with looping带有循环的数组中的布尔值
【发布时间】:2014-02-24 10:48:18
【问题描述】:

我正在模拟一些图形,在循环中为某些数组提供一些布尔条件时存在一些问题,这是代码

var check = false;
for (var k in GexfJS.graph.edgeList) { 
    var _edge = GexfJS.graph.edgeList[k]
    if ( (_edge.source == _curre) && ( _edge.target != _nodeIndex) ) {
        var _node = GexfJS.graph.nodeList[_edge.target];
        _str += '<li><div class="smallpill" style="background: ' + _node.color.base +'"></div><a href="#" onmouseover="GexfJS.params.activeNode = ' + _edge.target + '" onclick="displayNode(' + _edge.target + ', true); return false;">' + _node.label + '</a>' + ( GexfJS.params.showEdgeWeight && _edge.weight ? ' [' + _edge.weight + ']' : '') + '</li>';
    }
}

我的目标是,当边缘已被某个节点选择时,它不会再次选择节点,因为当边缘选择节点时它会有一些动作,在我的图中有很多来自节点的边缘。那么我如何将代码插入到上面的算法中,使用布尔条件为从边缘选择的节点提供条件?

【问题讨论】:

    标签: javascript jquery node.js


    【解决方案1】:

    不要使用布尔条件,只需尝试对象,如check={}; 然后放条件

    if ( (_edg.target == _curra) && (_edg.source != _nodeIndex)) {
        var _nod = GexfJS.graph.nodeList[_edg.source];
        if(check[_nod.label] != true){
            if(_n != _nod){
            _str += '';
            }
            }
            check[_nod.label] = true; 
        }
    

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 2015-05-24
      • 2017-06-04
      • 2013-08-09
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多