February 20, 2010

Iterating over JSON object (string ) with jquery

We had a scenario where in we need to search for particular object in collection. Whenever the user changes something in dropdown in ASP.NET we need to show some value in a label. If we take the drop down value to server it would take time.... so what we thot is we searialized the object using JavascriptSerializer in ASP.NET and converted to JSON string.. passsed to a javascript function to search.... (whenever dropdown changes)... I was literally amazed with the power of JSON and jquery combination... thot i would share with people in need.....

Here is the JSON string...in Javascript...

var obj = [{"Description":"No jquery pricing group may be used for Testing", "ID":1, "TempID":1, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":2, "TempID":2, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":3, "TempID":3, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":4, "TempID":4, "CompareID":3}, {"Description":"No jquery pricing group may be used for Testing", "ID":5, "TempID":1, "CompareID":4}, {"Description":"Jquery required for pricing Testing", "ID":6, "TempID":2, "CompareID":4}, {"Description":"Jquery required for pricing Testing", "ID":7, "TempID":3, "CompareID":4}, {"Description":"Jquery required for pricing Testing", "ID":8, "TempID":4, "CompareID":4}, {"Description":"No jquery pricing group may be used for Testing", "ID":9, "TempID":1, "CompareID":5}, {"Description":"Jquery required for pricing Testing", "ID":10, "TempID":2, "CompareID":5}, {"Description":"Jquery required for pricing Testing", "ID":11, "TempID":3, "CompareID":5}, {"Description":"Jquery required for pricing Testing", "ID":12, "TempID":4, "CompareID":5}];

We had a requirement to searhch the description for matching TempID and COmpareID...

Our Javascript function was amazingly...

function Myfunc(ID1,Exp1){jQuery.each(obj, function Test(x) { if (obj[x].TempID == ID1 && obj[x].CompareID == Exp1) //return obj[x].Description; alert(obj[x].Description);}); }

This would have helped you to understand the power of jqeury

30 comments:

Anonymous said...

從人生中拿走友誼,猶如從生活中移走陽光..................................................

Anonymous said...

It's great!!..................................................

Anonymous said...

如果你不思考未來,你便不會有未來..................................................

Anonymous said...

Knowledge is power.......................................................

Anonymous said...

沒有友情,人生何樂? ..................................................

Anonymous said...

ut聊天77p2p85cc85st85街視訊視訊聊天ava片a片下載成人情色色情影音視訊聊天洪爺影城洪爺免費視訊免費a片免費一對多utsogo論壇ut聊天室成人片免費看................

Anonymous said...

cool blog,期待更新........................................

Anonymous said...

成功等於目前,其他都是這句話的註解。

Anonymous said...

Good la........................................

Anonymous said...

開心不開心都是一天,祝您能夠笑著面對一切! ........................................

Anonymous said...

工作,是愛的具體化~~~~努力吧!......................................................

宛妹宛妹 said...

Better say nothing than nothing to the purpose...................................................

RochelleP_Higginson瓊文 said...

you‘re so smart!............................................................

Anonymous said...

亞洲東洋影片go2av 18美女成人網 UT視訊美女交友 A片 - A片-情色網 免費視訊聊天fairy 情人080百分百成人圖片 影音聊天fm358 美女交友artdab 熟女人影片 制服淫窟 嘟嘟情人色網 utshow 視訊聊天 獸皇影片分享區 104av成人音影城 後宮視訊交友 sex520貼片,日本av女優,色美眉,sex,成人 免費線上影片觀看 洪爺護士免費 aa 片 173liveshow 視訊美女 0401成人聊天室 utobe影片 hichannel免費影視 情色視訊影音聊天 人之初貼圖區 plus論壇玩美女人影音秀 85cc情人影城 UT影音視訊聊天室 援交友留言 avonline免費a片 85cc免費av影片 情色免費成人avdvd電影 A片-殺很大 檳榔西施摸奶圖片 成人情色,性愛自拍 亞洲藝人情人視訊網 fdz論壇 情人視訊網 d736 uthome 視訊聊天室 sex888入口情色小遊戲 後宮 視訊聊天 免費視訊辣妹情人視訊網 kk俱樂部wmti 無碼dvd一本道a片 視訊美女 視訊ggo 素人自拍et免費影片下載 hilive-免費視訊 a383girl影音 45avdvd免費影片 免費視訊聊天fm358

冠慧 said...

婚姻對男人來說是賭他的自由,對女人而言卻是賭她的幸福。..................................................................

Anonymous said...

要照顧身體歐~保重......................................................................

Anonymous said...

一定要保持最佳狀況呦,加油!!!期待你發表的新文章!.................................................................

Anonymous said...

所有的資產,在不被諒解時,都成了負債.................................................................

Anonymous said...

沈舟側畔千帆過,病樹前頭萬木春............................................................

Anonymous said...

人生之中,比冒險更危險的一件事:不去冒險。..................................................

Anonymous said...

你的部落格不錯哦,我來享受一下~~..................................................

Anonymous said...

人生有如洶湧的波濤,如果沒有岩石的阻擋,怎能激起美麗的浪花?............................................................

Anonymous said...

融會貫通的智慧,永遠不會被遺忘。..................................................

Anonymous said...

愛,拆開來是心和受兩個字。用心去接受對方的一切,用心去愛對方的所有。............................................................

Anonymous said...

所有的資產,在不被諒解時,都成了負債.................................................................

Anonymous said...

傻氣的人喜歡給心 雖然每次都被笑了卻得到了別人的心..................................................................

Anonymous said...

耐心是一株很苦的植物,但果實卻很甜美。..................................................

Anonymous said...

獲益不少,謝謝分享!............................................................

Anonymous said...

人不能像動物一樣活著,而應該追求知識和美德............................................................

Anonymous said...

君子立恆志,小人恆立志。................. ................................................