开发者

how can i add a function to json object which has __type attribute?

开发者 https://www.devze.com 2023-01-09 02:56 出处:网络
I am sending an object that i generated within a class from the server as a result of web service call.

I am sending an object that i generated within a class from the server as a result of web service call.

how can i add a function to json object which has __type attribute?

it is returning with __type and it's other attributes from server.

alt text

I want to add some function to this object to ca开发者_JAVA技巧ll 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!
   }
},
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号