- 无法返回knex查询结果
[代码]const { MonitorDB: config } = require([代码][代码]'../config'[代码][代码])[代码] [代码]/**[代码][代码] [代码][代码]* Get the latest temperature from DB[代码][代码] [代码][代码]*/[代码][代码]async [代码][代码]function[代码] [代码]get(ctx, next) {[代码] [代码] [代码][代码]const MonitorDB = require([代码][代码]'knex'[代码][代码])({[代码][代码] [代码][代码]client: [代码][代码]'mysql'[代码][代码],[代码][代码] [代码][代码]connection: {[代码][代码] [代码][代码]host: config.host,[代码][代码] [代码][代码]port: config.port,[代码][代码] [代码][代码]user: config.user,[代码][代码] [代码][代码]password: config.pass,[代码][代码] [代码][代码]database: config.db,[代码][代码] [代码][代码]charset: config.char,[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]MonitorDB([代码][代码]'temperature'[代码][代码]).select([代码][代码]'*'[代码][代码]).then([代码][代码]function[代码][代码](rows) {[代码][代码] [代码][代码]ctx.state.code = 200[代码][代码] [代码][代码]ctx.state.data = { msg: 23.5 }[代码][代码] [代码][代码]})[代码][代码] [代码][代码].[代码][代码]catch[代码][代码]([代码][代码]function[代码][代码](error) {[代码][代码] [代码][代码]console.log(error)[代码][代码] [代码][代码]tx.state.code = 500[代码][代码] [代码][代码]ctx.state.data = { msg: error }[代码][代码] [代码][代码]})[代码] [代码]}[代码]如上代码想实现一个get操作,这个操作会去查询DB,然后根据查询的结果返回不同的值。 但是每次API调用都不能then执行就返回了。我也知道这个then是异步调用,但是我怎么能够让这个get 函数停下来等待then执行,然后再返回呢?
2018-04-09 - Do not have detail handler in current
简单的在Demo实例的index.wxml加入了一个view,在其中bindtap="detailEvent",然后在对应的index.js里面定义了detailEvent方法,结果在调试点击这个view的时候,console总是不能log,并且console总是提示 “Do not have detail handler in current page: pages/index/index. Please make sure that detail handler has been defined in pages/index/index, or pages/index/index has been added into app.json”这就话。其实我的handler已经定义在了pages/index/index.js,而且pages/index/index也已经加入了app.json中。 具体代码如下: [图片] [图片] [图片]
2017-07-30