NodeJS 和 ThinkJS 使用时的注意点 (一)

来源:互联网 发布:高清网络电视在线观看 编辑:程序博客网 时间:2024/06/01 07:57

1、注意大小写,SQL中不区分,而nodejs中是区分的,而sql数据库很多都会自动转成小写,取出的数据JSON,NODEJS直接调用是很方便,但也容易出错


2、不能在URL中访问,404错误时,看看Controller中的方法名中有没有Action,好几次了,也可能是我的个案


4、for(let user of users){ 中的是 of , 而不是 in , 习惯了写 for ... in ...,然后语法检查是通过的,就是结果不对


5、ThinkJS的memory缓存没有想象中的快,比如下面的递归函数:

async getChildList(pid){    let codes = await this.getCodes();    let ret = [];    for(let code of codes){        if(code.c_pid == pid){            ret.push(code);            let childs =await this.getChildList(code.id);            for(let child of childs){ ret.push(child);  }        }    }    return ret;}
改成用参数传递数组就要快得多

async getChildList(pid,codes){    let ret = [];    for(let code of codes){        if(code.c_pid == pid){            ret.push(code);            let childs =await this.getChildList(code.id, codes);            for(let child of childs){ ret.push(child);  }        }    }    return ret;}


0 0