本文共 1982 字,大约阅读时间需要 6 分钟。
封装的sql log http 三大组件 在编辑器上的方法能代码智能提示
//DB处理器var db = this.tabris.create('SQL', { name:'testorm', type:'mysql'});//http处理器var http = this.tabris.create('HTTP', { method:'GET'});//log处理器var log = this.tabris.create('LOG', { trace:true});db.delete('delete from child_district');//从district表里面获取所有城市的Codevar get_district_sql = "select Code from district";var district_code_list = db.query(get_district_sql);for (var index = 0; index < district_code_list.length; index++) { getChildDistrictAndInsertToDb(district_code_list[index].Code);}//远程获取function getChildDistrictAndInsertToDb(parentCode){ log.info(parentCode); var re = http.getJson({ url:'https://fuwu.sf-express.com/service/address/newAddr/getNewSubAddress?parentCode=' + parentCode }); if(!re.subAddressList || !re.subAddressList.length) return; for (var index = 0; index < re.subAddressList.length; index++) { var child = re.subAddressList[index]; var insertSql = "insert into child_district (Name,Code,DataChange_LastTime) VALUES('"+ child.distCnName +"','"+ child.distCode +"',now())"; var insertResult = db.insert(insertSql) if(insertResult!=1){ log.error(child.distCnName + '插入db失败!'); }else{ log.info(child.distCnName + '插入db成功!') } }}
下载地址
https://pan.baidu.com/s/1dGZuodt9aMVKWyJ1F0byZw