2015.03.12-mysql union,jquery给Radio bind事件及操作,mysql函数查询树节点的所有子节点...

本文详细介绍了在企业信息系统中进行员工及部门管理的具体操作流程,并实现了通过MySQL函数递归查询所有子节点的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今日任务:
1.企业员工添加删除、部门添加编辑删除


实际:
完成70%


收获:
1.如何将企业信息表里面的id和name合并到部门表里面来?
用 union

select ep.id as id, ep.enterpriseName as name from enterprise ep
union
select d.id as id, d.departmentName as name from department d

2.input type=radio 实现赋值取值,利用jQuery绑定单击事件

$("input[type='radio']").bind("click", function(e){
var theEvent = window.event || e;
var theObj = theEvent.target || theEvent.srcElement;
var selectedValue = $(this).val();
if (selectedValue == "0")
{
$('input[name="' + theObj.name + '"][value="1"]').removeAttr("checked");
$('input[name="' + theObj.name + '"][value="0"]').attr("checked", true);
}
else
{
$('input[name="' + theObj.name + '"][value="0"]').removeAttr("checked");
$('input[name="' + theObj.name + '"][value="1"]').attr("checked", true);
}
});

// 打开Dialog时让后台传递过来的值处于选中状态
$('input[name=Sex][value="' + rowData.Sex + '"]').attr("checked", true);

// 提交时获取选中的值
Sex : $("input[name='Sex'][checked]").val();


3.mysql函数,先开启函数支持:

set Global log_bin_trust_function_creators=1;

然后写函数


cast(rootId as CHAR); concat(sTemp,',',sTempChd);
SELECT group_concat(id) INTO sTempChd FROM treeNodes where FIND_IN_SET(pid,sTempChd)>0;

eg:查询所有子节点,包括自己

Drop Function if exists getChildList
CREATE FUNCTION getChildList (rootId INT)
RETURNS varchar(1000)
BEGIN
DECLARE sTemp VARCHAR(1000);
DECLARE sTempChd VARCHAR(1000);

SET sTemp = '$';
SET sTempChd =cast(rootId as CHAR);

WHILE sTempChd is not null DO
SET sTemp = concat(sTemp,',',sTempChd);
SELECT group_concat(id) INTO sTempChd FROM treeNodes where FIND_IN_SET(pid,sTempChd)>0;
END WHILE;
RETURN sTemp;
END

//调用
select getChildList(10081);
// 输出 '$,10081,10086'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值