<CharlieDigital/> Programming, Politics, and uhh…pineapples

15Jul/08Off

Deleting ExtensionData From JavaScript

WCF DataContracts include an ExtensionData property which is a bit troublesome if you are trying to send a modified object back up to the service if it has no properties in Javascript.


So I wrote a little piece of Javascript to clean it up:


function DeleteExtensionData(obj) {
var keys = Object.keys(obj);

keys.each(function(key) {
if(!Object.isFunction(obj[key])) {
if(obj[key] instanceof Object) {
DeleteExtensionData(obj[key]);
}

if(key == "ExtensionData") {
delete obj[key];
}
}
});
}


It will recusively delete all ExtensionData properties from the object.  You can call as soon as you get the result from a completed AJAX request or you can call before sending an object parameter to a service.


Note that it uses constructs from prototype.


If you want to get fancy, you can also write a custom serializer.

Posted by Charles Chen

Filed under: WCF Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.

  • vocal
  • trap
  • trance
  • techno
  • symphonic-rock
  • spain
  • soundtrack
  • soul
  • singer
  • score
  • rock
  • rnb
  • reggaeton
  • reggae
  • rap
  • punk
  • progressive
  • post-grunge
  • pop
  • other
  • new-audio
  • metalcore
  • lounge
  • latino
  • jazz
  • instrumental
  • indie
  • house
  • hip-hop
  • heavy-metal
  • hard-rock
  • funk
  • folk
  • electronic
  • dubstep
  • drum-and-bass
  • downtempo
  • deep-house
  • dance
  • country
  • club-house
  • classical
  • classic-rock
  • chillout
  • breakbeat
  • blues
  • ambient
  • alternative-rock