鎴戜滑鏉ョ湅鐪嬮棴鍖呯殑鐢ㄩ€斻€備簨瀹炰笂锛岄€氳繃浣跨敤闂寘锛屾垜浠彲浠ュ仛寰堝浜嬫儏銆傛瘮濡傛ā鎷熼潰鍚戝璞$殑浠g爜椋庢牸锛涙洿浼橀泤锛屾洿绠€娲佺殑琛ㄨ揪鍑轰唬鐮侊紱鍦ㄦ煇浜涙柟闈㈡彁鍗囦唬鐮佺殑鎵ц鏁堢巼銆?/p>
1 鍖垮悕鑷墽琛屽嚱鏁?/p>
鎴戜滑鐭ラ亾鎵€鏈夌殑鍙橀噺锛屽鏋滀笉鍔犱笂var鍏抽敭瀛楋紝鍒欓粯璁ょ殑浼氭坊鍔犲埌鍏ㄥ眬瀵硅薄鐨勫睘鎬т笂鍘伙紝杩欐牱鐨勪复鏃跺彉閲忓姞鍏ュ叏灞€瀵硅薄鏈夊緢澶氬潖澶勶紝
姣斿锛氬埆鐨勫嚱鏁板彲鑳借鐢ㄨ繖浜涘彉閲忥紱閫犳垚鍏ㄥ眬瀵硅薄杩囦簬搴炲ぇ锛屽奖鍝嶈闂€熷害(鍥犱负鍙橀噺鐨勫彇鍊兼槸闇€瑕佷粠鍘熷瀷閾句笂閬嶅巻鐨?銆?br>闄や簡姣忔浣跨敤鍙橀噺閮芥槸鐢╲ar鍏抽敭瀛楀锛屾垜浠湪瀹為檯鎯呭喌涓嬬粡甯搁亣鍒拌繖鏍蜂竴绉嶆儏鍐碉紝鍗虫湁鐨勫嚱鏁板彧闇€瑕佹墽琛屼竴娆★紝鍏跺唴閮ㄥ彉閲忔棤闇€缁存姢锛?br>姣斿UI鐨勫垵濮嬪寲锛岄偅涔堟垜浠彲浠ヤ娇鐢ㄩ棴鍖咃細
var datamodel = { table : [], tree : {} }; (function(dm){ for(var i = 0; i < dm.table.rows; i++){ var row = dm.table.rows[i]; for(var j = 0; j < row.cells; i++){ drawCell(i, j); } } //build dm.tree })(datamodel);
聽聽
聽
鎴戜滑鍒涘缓浜嗕竴涓尶鍚嶇殑鍑芥暟锛屽苟绔嬪嵆鎵ц瀹冿紝鐢变簬澶栭儴鏃犳硶寮曠敤瀹冨唴閮ㄧ殑鍙橀噺锛?br>鍥犳鍦ㄦ墽琛屽畬鍚庡緢蹇氨浼氳閲婃斁锛屽叧閿槸杩欑鏈哄埗涓嶄細姹℃煋鍏ㄥ眬瀵硅薄銆?br>
2缂撳瓨
鍐嶆潵鐪嬩竴涓緥瀛愶紝璁炬兂鎴戜滑鏈変竴涓鐞嗚繃绋嬪緢鑰楁椂鐨勫嚱鏁板璞★紝姣忔璋冪敤閮戒細鑺辫垂寰堥暱鏃堕棿锛?br>閭d箞鎴戜滑灏遍渶瑕佸皢璁$畻鍑烘潵鐨勫€煎瓨鍌ㄨ捣鏉ワ紝褰撹皟鐢ㄨ繖涓嚱鏁扮殑鏃跺€欙紝棣栧厛鍦ㄧ紦瀛樹腑鏌ユ壘锛屽鏋滄壘涓嶅埌锛屽垯杩涜璁$畻锛?br>鐒跺悗鏇存柊缂撳瓨骞惰繑鍥炲€硷紝濡傛灉鎵惧埌浜嗭紝鐩存帴杩斿洖鏌ユ壘鍒扮殑鍊煎嵆鍙€傞棴鍖呮鏄彲浠ュ仛鍒拌繖涓€鐐癸紝鍥犱负瀹冧笉浼氶噴鏀惧閮ㄧ殑寮曠敤锛?br>浠庤€屽嚱鏁板唴閮ㄧ殑鍊煎彲浠ュ緱浠ヤ繚鐣欍€?/p>
var CachedSearchBox = (function(){ var cache = {}, count = []; return { attachSearchBox : function(dsid){ if(dsid in cache){//濡傛灉缁撴灉鍦ㄧ紦瀛樹腑 return cache[dsid];//鐩存帴杩斿洖缂撳瓨涓殑瀵硅薄 } var fsb = new uikit.webctrl.SearchBox(dsid);//鏂板缓 cache[dsid] = fsb;//鏇存柊缂撳瓨 if(count.length > 100){//淇濇缂撳瓨鐨勫ぇ灏?lt;=100 delete cache[count.shift()]; } return fsb; }, clearSearchBox : function(dsid){ if(dsid in cache){ cache[dsid].clearSelection(); } } }; })(); CachedSearchBox.attachSearchBox("input1");
聽聽聽
杩欐牱锛屽綋鎴戜滑绗簩娆¤皟鐢–achedSearchBox.attachSerachBox(鈥渋nput1鈥?鐨勬椂鍊欙紝
鎴戜滑灏卞彲浠ヤ粠缂撳瓨涓彇閬撹瀵硅薄锛岃€屼笉鐢ㄥ啀鍘诲垱寤轰竴涓柊鐨剆earchbox瀵硅薄銆?br>
3 瀹炵幇灏佽
鍙互鍏堟潵鐪嬩竴涓叧浜庡皝瑁呯殑渚嬪瓙锛屽湪person涔嬪鐨勫湴鏂规棤娉曡闂叾鍐呴儴鐨勫彉閲忥紝鑰岄€氳繃鎻愪緵闂寘鐨勫舰寮忔潵璁块棶锛?/p>
var person = function(){ //鍙橀噺浣滅敤鍩熶负鍑芥暟鍐呴儴锛屽閮ㄦ棤娉曡闂? var name = "default"; return { getName : function(){ return name; }, setName : function(newName){ name = newName; } } }(); print(person.name);//鐩存帴璁块棶锛岀粨鏋滀负undefine