码迷,mamicode.com
首页 > Web开发 > 详细

jquery easyui树形

时间:2015-09-05 19:27:47      阅读:333      评论:0      收藏:0      [点我收藏+]

标签: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");

}

}

});

}

技术分享

技术分享


本文出自 “新手学习中” 博客,谢绝转载!

jquery easyui树形

标签:jquery easyui树形

原文地址:http://9322128.blog.51cto.com/9312128/1691589

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!