Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 1.59 KB  |  hits: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Knockout.js: ko.toJSON does not convert viewmodel to JSON
  2. "{"__ko_mapping__":{"ignore":[],"include":["_destroy"],"copy":[],"mappedProperties": {"__type":true,"Prop1":true,"Prop2":true,"Prop3":true,"Prop4":true,"Prop5":true}}}"
  3.        
  4. {"__type":"DealerModel","Prop1":"","Prop2":"","Prop3":"","Prop4":"","Prop5":"Some Name  ltd"}}}"
  5.        
  6. [Serializable]
  7. Public class DealerModel
  8. {
  9.     public string Porp1 { get; set; }
  10.     public string Porp2 { get; set; }
  11.     public string Porp3 { get; set; }
  12.     public string Porp4 { get; set; }
  13.     public string Porp5 { get; set; }
  14. }
  15.        
  16. var jsonViewModel = '';
  17.             jsonViewModel = ko.toJSON(myNameSpace.ViewModel1);
  18.             jsonViewModel = jsonViewModel.replace(//Date((.*?))//gi, "new Date($1)");
  19.             saveArray[0] = jsonViewModel
  20.  
  21.             jsonViewModel = ko.toJSON(myNameSpace.ViewModel2);
  22.             jsonViewModel = jsonViewModel.replace(//Date((.*?))//gi, "new Date($1)");
  23.             saveArray[1] = jsonViewModel
  24.  
  25. $.ajax({
  26.                 type: "POST",
  27.                 url: "Services/SomeService.asmx/SaveObjects",
  28.                 cache: true,
  29.                 contentType: "application/json; charset=utf-8",
  30.                 data:"{args:" + ko.toJSON(saveArray) + "}",
  31.                 dataType: "json"
  32.             });
  33.        
  34. $.ajax({
  35.             type: "POST",
  36.             url: "Services/SomeService.asmx/SaveObjects",
  37.             data: { args: saveArray }
  38.         });
  39.        
  40. var mappingOptions = { };
  41. var data = { "FirstName": "Bruce". "LastName": "Banner" };
  42. var vmBad = ko.mapping.fromJS(mappingOptions, data);
  43. var vmGood = ko.mapping.fromJS(data, mappingOptions);