Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 3rd, 2012  |  syntax: None  |  size: 3.23 KB  |  views: 15  |  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. var addresses = "[";
  2.  
  3.          addresses += '{"AddressID":' + adressid + ',"EmailID":' + $('#txtemailData').val() + ',"Hno":' + $('#txthno').val() + ',"StreetName":' + $('#txtstreetname').val() + ',"City":' + $('#txtcity').val() + ',"StateID":' + $('#ddlState').val() + ',"CountryID":' + $('#ddlcountry').val() + ',"Zip":' + $('#txtzip').val() + ',"PhoneNumber":' + $('#txtphonenumber').val() + ',"Fax":' + $('#txtfax').val() + ',"AddressName:' + $('#txtaddresstype').val() + '"},';
  4.        
  5. [{
  6.    "AddressID":2,
  7.    "EmailID":akanilkumar443@gmail.com,
  8.    "Hno":Hyderabad,
  9.    "StreetName":Gachibowli,
  10.    "City":Hyderabad,
  11.    "StateID":1,
  12.    "CountryID":1,
  13.    "Zip":040,
  14.    "PhoneNumber":8341516166,
  15.    "Fax":23123131,
  16.    "AddressName:Store Address"},
  17.  {
  18.    "AddressID":3,
  19.    "EmailID":akanilkumar443@gmail.com,
  20.    "Hno":aSAs,
  21.    "StreetName":asdasdad,
  22.    "City":asdasda,
  23.    "StateID":1,
  24.    "CountryID":1,
  25.    "Zip":asdasda,
  26.    "PhoneNumber":asdasda,
  27.    "Fax":asdasda,
  28. "AddressName:Store Type"
  29. }]
  30.        
  31. function EditAddress(addressid) {
  32.     alert(addressid);
  33.     alert(addresses);
  34.     var addressobject =JSON.parse(addresses.substring(0, addresses.length - 1) + ']');
  35.     jQuery.each(addressobject, function (i, val) {
  36.         alert(val.AddressID);
  37.         if (val.AddressID == addressid)
  38.         {
  39.             //update logic
  40.         }
  41.     });
  42. }
  43.        
  44. var addressesAsArray = [],
  45.     addressAsObject = {}
  46.     address;
  47. //assuming some loop or other
  48. address = {
  49.               "AddressID": adressid,
  50.               "EmailID":$('#txtemailData').val(),
  51.               "Hno":$('#txthno').val(),
  52.               "StreetName": $('#txtstreetname').val(),
  53.               "City": $('#txtcity').val(),
  54.               "StateID": $('#ddlState').val(),
  55.               "CountryID": $('#ddlcountry').val(),
  56.               "Zip": $('#txtzip').val(),
  57.               "PhoneNumber": $('#txtphonenumber').val(),
  58.               "Fax": $('#txtfax').val(),
  59.               "AddressName": $('#txtaddresstype').val()
  60.           };
  61. addressesAsArray.push(address);
  62. addressAsObject[address.AddressID] = address;
  63.        
  64. address = addressesAsObject[addressIDBeingSought];
  65.        
  66. for(i = 0, len = addressesAsArray.length;i<len; i += 1){
  67.    if(addressesAsArray[i].AddressID === addressIDBeingSought) {
  68.        address = addressesAsArray[i];
  69.        break;
  70.    }
  71. }
  72.        
  73. json = JSON.stringify(adresses);
  74.        
  75. var testObject = [
  76.         {"id": "1", "name": "Apple"  , "isVisible": false},
  77.         {"id": "2", "name": "Orange", "isVisible": false}
  78.     ]
  79.  
  80. $(testObject).each(function() {
  81.     if(this.id == 2){
  82.       alert("current " + this.id + " = " + this.isVisible);
  83.       this.isVisible = true;
  84.       alert("changed " + this.id + " = " + this.isVisible);
  85.     }
  86. });
  87.        
  88. <!DOCTYPE>
  89.     <html>
  90.     <head>
  91.         <script type="text/javascript" src="linq.js"></script>
  92.     </head>
  93.     <body>
  94.     <script>  
  95.     var array = [{
  96.        AddressID:2,
  97.        EmailID:'akanilkumar443@gmail.com',
  98.        Hno:'Hyderabad'
  99.        },
  100.      {
  101.        AddressID:3,
  102.        EmailID:'akanilkumar443@gmail.com',
  103.        Hno:'aSAs'
  104.     }];
  105.     Enumerable.From(array).Where("$.AddressID == 3").ToArray()[0].Hno= 'ololo';
  106. // or this:
  107. // Enumerable.From(array).Where(function(x){return x.AddressID == 3}).ToArray()[0].Hno= 'ololo';
  108.     alert(array[1].Hno)  
  109.     </script>
  110.     </body>
  111.     </html>
clone this paste RAW Paste Data