在小程序的请求API中,变量是通过异步方式返回的,即要通过一个回调函数success()来返回结果,但是,在使用这个API的函数时,这个函数是不能被直接调用的,即不能
var data = home.getBannerData(id);这样来接收的。因此,可在这个使用API的函数中(注:此函数是在home-module.js中定义的,即专门用来处理数据,当做模型的一个js文件),传递一个参数,这个参数是一个函数,在回调函数success()中使用这个函数,形如这样

接下来,只要在控制器层home.js定义好这个函数

并使用

就成!
网友评论