我怎么可以添加一个函数json对象具有__type属性? [英] how can i add a function to json object which has __type attribute?
问题描述
我发送了一个对象,这是我在服务器中通过Web服务调用在服务器中生成的一个对象。
$ b
替代文字http://www.freeimagehosting.net/uploads/d9f659d369.png
它以__type返回,它来自服务器的其他属性。
alt text http:// www .freeimagehosting.net / uploads / 825a696318.png
我想为这个对象添加一些函数,以便在我的文件中随处调用。
我怎么能做到这一点?
谢谢...
那么,如果我找到了正确的答案,那么您希望为返回的对象添加一个函数()
。由于您不允许在 JSON对象内传输可执行的JavaScript代码
,因此您无法添加函数serverside。
所以你必须在你的客户创建你的javascript对象后向该对象添加一个方法/属性。像
success:function(data){
data.my_new_method = function(){
//好极了!
}
},
I am sending an object that i generated within a class from the server as a result of web service call.
alt text http://www.freeimagehosting.net/uploads/d9f659d369.png
it is returning with __type and it's other attributes from server.
alt text http://www.freeimagehosting.net/uploads/825a696318.png
I want to add some function to this object to call from everywhere easly in my files.
How can i achieve this?
Thanks...
Well if I get you right, you want to add a function()
to the returned object. You can't add a function serverside, since you are not allowed to transfer executable javascript code within a JSON object
.
So you would have to add a method/property to that object after your client has created your javascript object. like
success: function(data){
data.my_new_method = function(){
// yay!
}
},
这篇关于我怎么可以添加一个函数json对象具有__type属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!