我有一个对象。
reqeuest ={"_command":".login","username":"rahul","password":"12345"}
我想添加
{'on':{
login:function(){
console.log("logged in ");
},
error:function(){
console.log("oops error ");
}
}}
所以它会变得像它:
{
"_command":".login","username":"rahul","password":"12345",
'on':{
login:function(){
console.log("logged in ");
},
error:function(){
console.log("oops error ");
}
}}
我试过的是
request=$.extend(request,{'on':{
login:function(){
console.log("logged in ");
},
error:function(){
console.log("oops error ");
}
}});
或
hash.extend(request,{'on':{
login:function(){
console.log("logged in ");
},
error:function(){
console.log("oops error ");
}
}});
但它没有做我需要做什么?
答案 0 :(得分:1)
request.on = {
login: function() {
console.log("logged in ");
},
error: function() {
console.log("oops error ");
}
}
答案 1 :(得分:0)
你应该这样做:
request["on"] = {
login:function(){
console.log("logged in ");
},
error:function() {
console.log("oops error ");
}
};
要测试它,请转到firebug中的Script选项卡,然后在'Watch'选项卡上写'request'。它正在发挥作用。 干杯