device-cat-select-jqcontrol.js 1.85 KB
!function($){$.extend({initcat:function(e,p){p=$.extend({urlOrData:null,deviceParentCat:"",deviceChildCat:"",animate:{showClass:"",hideClass:""},onChoice:!1},p);var deviceParentCat=p.deviceParentCat?p.deviceParentCat:"deviceParentCat",deviceChildCat=p.deviceChildCat?p.deviceChildCat:"deviceChildCat",option={_LoadParentCat:function(control,getDeviceCatListURL){$.ajax({type:"post",url:getDeviceCatListURL,dataType:"json",data:$.csrf({parentId:0}),success:function(msg){if(1==msg.status){var data=eval(msg.modelList),html="<option value=''>--请选择--</option>";for(var s in data)html=html+"<option value='"+data[s].id+"'>"+data[s].name+"</option>";$(control).html(html)}else alert("加载失败")},error:function(msg){alert("加载异常")}})},_Change:function(pid,getDeviceCatListURL,childselect){return""==pid?($("#"+childselect).html("<option value=''>--请选择二级分类--</option>"),!1):void $.ajax({type:"post",url:getDeviceCatListURL,dataType:"json",data:$.csrf({parentId:pid}),success:function(msg){if(1==msg.status){var data=eval(msg.modelList),html="<option value=''>--请选择二级分类--</option>",cat_id=$("#hid_cat_id").val();for(var s in data)html=parseInt(cat_id)==parseInt(data[s].id)?html+"<option value='"+data[s].id+'\' selected="selected">'+data[s].name+"</option>":html+"<option value='"+data[s].id+"'>"+data[s].name+"</option>";$("#"+childselect).html(html)}else alert("加载失败")},error:function(msg){alert("加载异常")}})},loadData:function(){if("string"==typeof p.urlOrData){option._LoadParentCat($("#"+deviceParentCat),p.urlOrData);var pid=$("#"+deviceParentCat).val();option._Change(pid,p.urlOrData,deviceChildCat)}}};option.loadData(),$(e).bind("change",function(){var pid=$("#"+deviceParentCat).val();option._Change(pid,p.urlOrData,deviceChildCat)})}}),$.fn.extend({initcat:function(p){return this.each(function(){$.initcat(this,p)})}})}(jQuery);