无法找出我逻辑中的“未定义”

时间:2018-11-02 05:20:19

标签: angular logic

我正在创建一条语句,在该语句中,我基于下拉列表中的输入来插入值。而且我能够创建一个声明。但是,当我合并语句片段时,我在开头和中间出现“未定义”。我无法确定这是什么以及为什么“未定义”。请帮忙。 编码是在angular2中进行的,但我认为这只是一个逻辑问题。

逻辑- 代码-

app.component.ts

// For arranging a unit and number of commas.
      for (var i = 0; i < this.subNodeItemLength; i++) {

        this.unit[i] = ", ( " + this.letter[i] + ":" + this.subnodeSelectItemtext[i] + " ) - [" + this.letter[i + 1] + " ] - ( " +
          this.letter[i + 2] + ") ";

        this.units.push(this.unit[i]);
        console.log("units = ", this.units);
        this.commas.push(this.comma);
        console.log("commas", this.commas);
        console.log("comma =", this.comma);
      }

      // Complete Statement

      for (var i = 0; i < this.subNodeItemLength; i++) {

        console.log("before statement logic = ", this.statement)


        this.statement[i] += (this.units[i] + this.commas[i - 1]);


        console.log("After logic, statement =", this.statement[i]);
      }
      console.log("final statement =", this.statement);

      // After RETURN 

      for (var i = 0; i < this.subNodeItemLength; i++) {

        this.afterReturn += this.letter[i] + this.commas[i - 1];
      }

      // Cypher Query

      this.cypherQuery = "MATCH (xab:" + this.rootItemText + " ) OPTIONAL MATCH (xab: " + this.rootItemText + ")-[r1]-(p1)" +
        this.statement + "RETURN xab,r1,p1 ," + this.afterReturn;

输出-

units =  [", ( a:SMS ) - [b ] - ( c) "]

commas [","]

 comma = ,

units =  (2) [", ( a:SMS ) - [b ] - ( c) ", ", ( b:Collection ) - [c ] 
- ( d) "]

 commas (2) [",", ","]

comma = ,

 units =  (3) [", ( a:SMS ) - [b ] - ( c) ", ", ( b:Collection ) - [c 
  ] - ( d) ", ", ( c:Payments ) - [d ] - ( e) "]

 commas (3) [",", ",", ","]

 comma = ,

 before statement logic =  []

 After logic, statement = undefined, ( a:SMS ) - [b ] - ( c) undefined



before statement logic =  ["undefined, ( a:SMS ) - [b ] - ( c) undefined"]

After logic, statement = undefined, ( b:Collection ) - [c ] - ( d) ,

before statement logic =  (2) ["undefined, ( a:SMS ) - [b ] - ( c) undefined", "undefined, ( b:Collection ) - [c ] - ( d) ,"]

After logic, statement = undefined, ( c:Payments ) - [d ] - ( e) ,

 final statement = (3) ["undefined, ( a:SMS ) - [b ] - ( c) undefined", "undefined, ( b:Collection ) - [c ] - ( d) ,", "undefined, ( c:Payments ) - [d ] - ( e) ,"]



 NeoVis {_config: {…}, _encrypted: "ENCRYPTION_OFF", _trust: "TRUST_ALL_CERTIFICATES", _driver: Driver, 

_query: 
"MATCH (xab:Century ) OPTIONAL MATCH (xab: Century)…- ( e) ,RETURN xab,r1,p1 ,undefinedaundefinedb,c,", …}


    neovis.js:36680 Error: Invalid input 'd': expected 'w/W' or 'i/I' (line 1, column 63 (offset: 62))

    "MATCH (xab:Century ) OPTIONAL MATCH (xab: Century)-[r1]-(p1)undefined, ( a:SMS ) - [b ] - ( c) undefined,undefined, ( b:Collection ) - [c ] - ( d) ,,undefined, ( c:Payments ) - [d ] - ( e) ,RETURN xab,r1,p1 ,undefinedaundefinedb,c,"

1 个答案:

答案 0 :(得分:1)

在第二个和第三个for循环中,索引从0开始,因此第一次通过循环i ===0。但是,然后,您尝试获取this.commas[i - 1]的值。由于i === 0,这意味着您正在尝试为this.commas[-1]查找一个未定义的值。