jquery easyui樹形


/*html

<tr>

<td width="50" align="right"><div class="divSty2"><label>請選擇從業方向:</label></div></td>

<td>

<select id="txtjobDirection" class="easyui-combotree" multiple style="width:200px;"></select>

</td>

</tr>

<tr>

<td align="right" ><label >請選擇區域:</label></td>

<td >

<div class="divSty5">

<label>省<select id="txtProvince" class="easyui-combobox" name="txtProvince" style="width:200px;"

editable="false" data-options="valueField:'id',textField:'text'"></select></label>

<label>市/縣<select id="txtCity" class="easyui-combotree" multiple style="width:200px;"

></select></label>

</div>

</td>

</tr>

*/


/**

* 判斷非空

* @param val

* @returns {Boolean}

*/

function isEmpty(val) {

val = val.trim();

if (val == null)

return true;

if (val == undefined || val == 'undefined')

return true;

if (val == "")

return true;

if (val.length == 0)

return true;

if (!/[^(^\s*)|(\s*$)]/.test(val))

return true;

return false;

};


function isNotEmpty(val) {

return !isEmpty(val);

};

/**

* 從業方向下拉選擇

*/

function queryJobDirection(){

$.get("queryJobDirection.action",function(obj){

var catN = obj.data.length;

var data = [{"id":"root","text":"全部","checked":true,children:[]}];

for(var i=0;i<catN;i++){

var childsN = obj.data[i].childs.length;

var res ={"id":"","text":obj.data[i].childs[0].catalogName,children:[]}; 

for(j=0;j<childsN;j++){

var children = {"id":obj.data[i].childs[j].id,"text":obj.data[i].childs[j].name}; 

res.children.push(children);

}

data[0].children.push(res); 

}

$("#txtjobDirection").combotree("loadData",data);

});

}

/**

* 省下拉選擇

*/

function province(){

$.get("queryRootArea.action",function(obj){

var catN = obj.data.length;

var data = [];

for(var i=0;i<catN;i++){

var res ={"id":obj.data[i].id,"text":obj.data[i].name}; 

data.push(res); 

}

$("#txtProvince").combobox("loadData",data);

});

}

/**

* 點擊省事件

*/

function eventProvince(){

$("#txtProvince").combobox({

onSelect: function(param){

var parentId =$("#txtProvince").combobox("getValue");

$.post("queryChildArea.action",{"parent":parentId},function(obj){

var catN = obj.data.length;

var data = [];

for(var i=0;i<catN;i++){

var res ={"id":obj.data[i].id,"text":obj.data[i].name,children:[]}; 

data.push(res); 

}

$("#txtCity").combotree("loadData",data);

});

}

});

}

/**

* 點擊市事件

*/

function eventCity(){

$('#txtCity').combotree({

onSelect: function(node){

if(node.children.length == 0){

$.post("queryChildArea.action",{"parent":node.id},function(obj){

var catN = obj.data.length;

var data = [];

for(var i=0;i<catN;i++){

var res ={"id":obj.data[i].id,"text":obj.data[i].name}; 

data.push(res); 

}

$('#txtCity').combotree("tree").tree('append',{parent:node.target,data:data});

});

}

}

});

}

/**

* 刪數組個下標

*/

Array.prototype.baoremove = function(dx){

   if(isNaN(dx)||dx>this.length){return false;}

   this.splice(dx,1);

}

/**

* 添加數組中的值

*/

    Array.prototype.insert = function (index, item) {  

        this.splice(index, 0, item);  

      };  

  /**

  * 推送按鈕事件

  */

function eventBtn(){

$("#btnPush").click(function(){

var jobDirections = $('#txtjobDirection').combotree('getValues');

if(jobDirections.length == 0){

$.messager.alert("提示","請選擇從業方向!!","info");

return;

}else{

if(jobDirections[0] == "root"){

jobDirections = ["root"];

}else{

for(var key in jobDirections){

if(jobDirections[key] == ""){

jobDirections.baoremove(key);

}

}

}

}

jobDirections = JSON.stringify(jobDirections)

 

var Province = $('#txtProvince').combobox('getValue');

if(isEmpty(Province)){

$.messager.alert("提示","請選擇區域!!","info");

return;

var Citys = $('#txtCity').combotree('getValues');

if(Citys.length == 0){

Citys = [Province];

}else{

Citys.insert(0,Province);

}

Citys = JSON.stringify(Citys);

var InfoRate = $("input[name='rdoInfoRate']:checked").val();

var Identifion = $("input[name='rdoIdentifion']:checked").val();

var Business = $("input[name='rdoBusiness']:checked").val();

var Specialist = $("input[name='rdoSpecialist']:checked").val();

var Content = $.trim($("#txtContent").val());

var data ={

content:Content,

jobDirection:jobDirections,

area:Citys,

infoRate:InfoRate,

identifionAuth:Identifion,

businessAuth:Business,

specialistAuth:Specialist

}

$.post("addManpowerBlog.action",data,function(obj){

if (obj.status == 0) {

$.messager.alert("提示", obj.message, "info");

$("#txtContent").val("");

} else {

$.messager.alert("錯誤", obj.message, "error");

}

});

});

}

/**

* 點擊市縣下拉麪板顯示的時候觸發。

*/

function showPanel(){

$("#txtCity").combotree({

onShowPanel: function(){

var Citys = $("#txtCity").combotree("tree").tree("getRoots");

if(Citys.length == 0){

$.messager.alert("提示","請選擇省!!","info");

}

}

});

}

wKiom1XqtmGxHeNoAAESAY8yAOY389.jpg

wKioL1XquIfQozMbAAGFw3ZxDaw635.jpg


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章