我是新手mithril js开发人员,我使用web服务创建示例代码mithril js获取控制器中的数据返回值。我很困惑请帮助。我创建了以下代码
模型
var User = {
userlist:function(){
return m.request({
method:'GET',
url:'//localhost:6500/getAllusers',
config:function(xhr, options){
xhr.setRequestHeader('x-access-token', Auth.token())
}
})
}
}
控制器
var home ={
controller:function(){
this.pages = Users.userlist()
}
}
答案 0 :(得分:1)
你可以这样做:(使用m.request(args).then())
var User = {
got_user_data:function(data){
//data is what you get from url:'//localhost:6500/getAllusers'
},
userlist:function(){
return m.request({
method:'GET',
url:'//localhost:6500/getAllusers',
config:function(xhr, options){
xhr.setRequestHeader('x-access-token', Auth.token())
}
}).then(User.got_user_data);
}
}