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

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值