我正在为使用宁静风格的 Web 服务的移动应用程序编写客户端。
var globApp = {
sessionId : "",
lastActionName: "",
userName : "2victor",
md5Pwd : "1234",
hostApiPath : "http://host/api",
action : {
login : {
scriptPath : "/acc/login",
method : "PUT",
requestParams : {
user : this.userName,
pwd : this.md5pwd
},
responseParams : {
}
},
register : {
scriptPath : "/acc/reg",
method : "POST",
requestParams : {
user : "myUserName",
fname : "myFirstName" ,
lname : "myLastName" ,
email : "mail@mail.com" ,
age : "28" ,
gender : "male" ,
pwd : "1234" ,
priv : "good"
},
responseParams : {
}
}
}
}
属性 userName 和 md5pwd 将在应用程序启动时分配。我想要实现的是,将此值分配给每个操作的 requestParams 对象下的 user 和 pwd 属性。当然,使用 this 不起作用并返回 undefined 原因,如果我理解正确的话,在这种情况下 this 指的是嵌套对象。
此 requestParams 对象由 AJAX 作为 JSON 发送。
我可以从这个对象中定义几个变量并使用它们,但我不想这样做。
怎么做?