SHARE
TWEET

Untitled

a guest Feb 21st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var requestData = { __batchRequests: [ { __changeRequests: [
  2. { requestUri: "Customers", method: "POST", headers: { "Content-ID": "1" }, data: {
  3.     CustomerID: 400, CustomerName: "John"
  4. }  }
  5. ] } ] };
  6.    
  7. var requestData = {};
  8. requestData.__batchRequests = [];
  9. requestData.__batchRequests[0] = {};
  10. requestData.__batchRequests[0].__changeRequests = [];
  11. requestData.__batchRequests[0].__changeRequests[0] = {};
  12. requestData.__batchRequests[0].__changeRequests[0].requestUri = "Customers";
  13. requestData.__batchRequests[0].__changeRequests[0].method = "POST";
  14. requestData.__batchRequests[0].__changeRequests[0].headers = { "Content-ID" : "1" };
  15. requestData.__batchRequests[0].__changeRequests[0].data = {};
  16.    
  17. var changeRequest = {
  18.     requestUri : "Customers",
  19.     method : "POST",
  20.     headers : { "Content-ID" : "1" },
  21.     data : {}
  22. };
  23.    
  24. requestData.__batchRequests[0].__changeRequests.push(changeRequest);
  25.    
  26. changeRequest.data.CustomerName = "Bob";
  27. changeRequest.data.CustomerID = "204";
  28.  
  29.  
  30. requestData.__/*...*/changeRequests[0].data.CustomerName; // Bob
  31.    
  32. function extend (obj, additions) {
  33.     var key;
  34.     for (key in obj) { if (additions.hasOwnProperty(key)) {
  35.         obj[key] = additions[key];
  36.     }
  37. }
  38.  
  39. function makeChangeRequest (url, method, headers, data) {
  40.     var request = {
  41.         requestUri : url,
  42.         method : method,
  43.         headers : {},
  44.         data : {}
  45.     };
  46.  
  47.     extend(request.headers, headers);
  48.     extend(request.data, data);
  49.  
  50.     return request;
  51. }
  52.  
  53. function getBatch (num) { return requestData.__batchRequests[num]; }
  54.  
  55.  
  56. var changeReq = makeChangeRequest("Customers",
  57.                                   "POST",
  58.                                   { "Content-ID" : "1" },
  59.                                   { CustomerName : "Bob", CustomerID : "2012" });
  60.  
  61. var batch = getBatch(0);
  62.  
  63. batch.__changeRequests.push(changeReq);
  64.    
  65. extend(changeReq.data, { Address : "33 Nowhere Rd.", City : "Splitsville" });
  66.    
  67. var requestData = { __batchRequests: [ { __changeRequests: [
  68. { requestUri: "Customers", method: "POST", headers: { "Content-ID": "1" }, data: {}  }
  69. ] } ] };
  70.    
  71. var customerDeetsArray =[{CustomerID: 400}, {CustomerName: "John"}];
  72.  
  73. for (var i in customerDeetsArray) {
  74.   requestData.data = $.extend(requestData.data, customerDeetsArray[i]);
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top