树形点击
开发工具与关键技术:JS
作者:赵纯雨
班级:1803
撰写时间:2019.7.13
在页面当中,放一个按钮,点击它,弹出一个商品游览弹出框,在商品游览弹出框里面,通过点击左侧的树形图查询数据,数据就会在layui表格里展示出来,当你点击左侧树形图的上衣时,他会在表格里面出现一条数据,我只加了一条数据,然后你再点击裤子的时候,因为我没添加数据,所以他是无数据的,如下图:
上面这张就是当你点击上衣的时候,出现了一条数据,
下面这张,就是当你点击裤子的时候,他是无数据的。
代码如下:
控制器代码:
public ActionResult SelectCommodity(LayuiTablePage layuiTablePage, string SXXM, string CXSJ, int? CategoryManagementID)
{
var list = myModel.B_CommodityManagement.Select(S => S.StyleNumber.Trim()).ToList();
List listReslut = new List();
List list2 = new List();
foreach (var item in list)
{
if (!list2.Contains(item))
{
list2.Add(item.Trim());
}
}
for (int i = 0; i < list2.Count(); i++)
{
var Num = list2[i];
var listCommodity = (from tbCommodityManagement in myModel.B_CommodityManagement
join tbCommodityList in myModel.B_CommodityList on tbCommodityManagement.CommodityManagementID equals tbCommodityList.CommodityManagementID
join tbQuantityInStock in myModel.S_QuantityInStock on tbCommodityManaement.QuantityInStockID equals tbQuantityInStock.QuantityInStockID
join tbColorManagement in myModel.D_ColorManagement on tbCommodityList.ColorManagementID equals tbColorManagement.ColorManagementID
join tbSize in myModel.D_Size on tbCommodityList.SizeID equals tbSize.SizeID
join tbSizeManagement in myModel.D_SizeManagement on tbSize.SizeManagementID equals tbSizeManagement.SizeManagementID
join tbCategoryManagement in myModel.D_CategoryManagement on tbCommodityManagement.CategoryManagementID equals tbCategoryManagement.CategoryManagementID
where tbCommodityManagement.StyleNumber.ToString() == Num
orderby tbCommodityManagement.CommodityManagementID descending
select new commodity
{
CategoryManagementID = tbCategoryManagement.CategoryManagementID,
ProductName = tbCommodityManagement.ProductName,
StyleNumber = tbCommodityManagement.StyleNumber,
TagPrice = tbCommodityManagement.TagPrice,
productCode = tbCommodityList.productCode,
SizeName = tbSizeManagement.SizeName,
ColorName = tbColorManagement.ColorName,
Amount = tbQuantityInStock.Amount,
Bargain = tbCommodityManagement.Bargain,
Putaway = tbCommodityList.Putaway,
}).ToList();
listCommodity[0].CommodityManagementID = listCommodity.Sum(S => S.CommodityManagementID);listReslut.Add(listCommodity[0]);
}树形图视图代码:
//获取点击的节点
function zTreeOnClick(e, treeId, treeNode) {
pId = treeNode.pId;
CategoryManagementID = treeNode.id;
console.log(CategoryManagementID)
var SXXM = $("#SXXM").val();
var CXSJ = $("#CXSJ").val();
selectSJ(CategoryManagementID);
}
//定义一个方法
function selectSJ(CategoryManagementID) {
var SXXM = $("#SXXM").val();
var CXSJ = $("#CXSJ").val();
if (CategoryManagementID == null) {
CategoryManagementID = 0;
}
TabTitles = layuiTable.reload(“employee”, {
url: “/DailyRoutine/CommodityManagement/SelectCommodity”,
page: {
curr: 1
},
where: {
SXXM: SXXM, CXSJ: CXSJ, CategoryManagementID: CategoryManagementID
}
});
}
//给树形图不同层次加上不同的图片
function SetIcon() {
var treeObj = $.fn.zTree.getZTreeObj(“treeDemo”);//树形
var two = treeObj.getNodesByParam(“level”, 1, null);
for (var i = 0; i < two.length; i++) {
$(two[i]).attr(“icon”, “/Plugins/treeImag/two.png”);
};
var two = treeObj.getNodesByParam(“level”, 2, null);
for (var i = 0; i < two.length; i++) {
$(two[i]).attr(“icon”, “/Plugins/treeImag/two.png”);
};
var two = treeObj.getNodesByParam(“level”, 3, null);
for (var i = 0; i < two.length; i++) {
$(two[i]).attr(“icon”, “/Plugins/treeImag/two.png”);
};
var two = treeObj.getNodesByParam(“level”, 4, null);
for (var i = 0; i < two.length; i++) {
$(two[i]).attr(“icon”, “/Plugins/treeImag/two.png”);
};
var two = treeObj.getNodesByParam(“level”, 5, null);
for (var i = 0; i < two.length; i++) {
$(two[i]).attr(“icon”, “/Plugins/treeImag/two.png”);
};
}