var stream = weex.requireModule('stream')
stream.fetch({
method: 'POST',
type: 'json',
url: map.requestUrl,
body: map.requestJson
}, function (ret) {
native.logger('request end....' + ret.status + ' ok ? ' + ret.ok)
if (!ret.ok) {
native.logger(map.requestUrl + ' request failed.........')
} else {
native.logger(map.requestUrl + ' request success........')
self.listData = ret.data
}
}, function (response) {
// progress...
}
)�
当 type 被定义为 ‘json’ 或者 ‘jsonp’ 时 返回值默认为一个 JSON 对应,否则默认是 String
JSON对象可以使用 JSON.stringify(ret.data)
; 转换成 String 输出日志等,不过一般情况下,JS是需要JSON对象作为参数传递的,因此直接使用 ret.data
即可
body值是请求的json字符串,而不是json对象
Stream 相关的请求,返回具体的参数列表在此查看,官方Demo查看
注意:在JSCallback方法中,如果需要引用整个index入口js的实例,不能直接使用 this, 而是在入口方法中用类似 var self = this
的方式存储起来,方便内联回调方法各处的调用(具体的使用案例)