[英]jqtree click event not working on partial view
我正在使用jqtree通過類別過濾產品。 它在我第一次單擊類別時起作用。 選擇類別后,我將單擊搜索按鈕以部分視圖顯示項目數據。 然后,當我將選擇另一個類別以搜索另一組數據時,單擊事件將不再起作用。
我使用的jQuery代碼:
function SearchProducts() {
var dataToSave = ko.toJSON({
productname: $('#txtProductName').val(),
categoryId: $('#lblCategoryID').text()
});
var url = '@Url.Action("AddEditProduct", "Inventory")';
$.ajax(url, {
data: dataToSave,
type: "post",
contentType: "application/json",
success: function (result) {
$("#addeditproduct").html(result);
}
});
};
$(function () {
var url = '@Url.Action("GetCategoryTreeView","Inventory")'
$('#SelectedCategoryID').text();
$('#tree1').tree({
dataUrl: url,
autoOpen: 1,
selectable: true
});
});
$('#tree1').bind(
'tree.click',
function (event) {
var node = event.node;
SelectedCategory = '';
lblParentID = '';
lblParentName = '';
$('#SelectedCategoryID').text('');
lblParentID = node.ID;
lblParentName = node.name;
SelectedCategory = 'Category Selected: ' + node.name + ' (Category ID: ' + lblParentID + ')';
$('#SelectedCategoryID').text(SelectedCategory);
$('#lblCategory').text(node.name + ' (' + lblParentID + ')');
lblCatID = lblParentID;
$('#lblCategoryID').text(lblParentID)
}
);
控制器上用於搜索產品的代碼
[HttpPost]
public ActionResult AddEditProduct(VMAddEditProduct viewModel)
{
var user = db.Users.Where(u => u.Username == this.User.Identity.Name).Single();
dynamic items = null;
if (viewModel.CategoryId != 0)
{
if (viewModel.ProductName != null && viewModel.ProductName != "")
{
items = (from product in db.tblFMSItems
join category in db.FMSCategory on product.CategoryID equals category.ID
where product.CenterID == user.CenterId
&& product.CategoryID == viewModel.CategoryId
&& product.ProductName == viewModel.ProductName
select new
{
CategoryId = product.CategoryID,
ProductId = product.ProductId,
ProductName = product.ProductName,
CategoryName = category.ProductType,
SKU = product.SKU,
Desc = product.Desc
})
.OrderBy(product => product.ProductName)
.ToList();
}
else
{
items = (from product in db.tblFMSItems
join category in db.FMSCategory on product.CategoryID equals category.ID
where product.CenterID == user.CenterId
&& product.CategoryID == viewModel.CategoryId
select new
{
CategoryId = product.CategoryID,
ProductId = product.ProductId,
ProductName = product.ProductName,
CategoryName = category.ProductType,
SKU = product.SKU,
Desc = product.Desc
})
.OrderBy(product => product.ProductName)
.ToList();
}
}
else if (viewModel.ProductName != null && viewModel.ProductName != "")
{
items = (from product in db.tblFMSItems
join category in db.FMSCategory on product.CategoryID equals category.ID
where product.CenterID == user.CenterId
&& product.ProductName == viewModel.ProductName
select new
{
CategoryId = product.CategoryID,
ProductId = product.ProductId,
ProductName = product.ProductName,
CategoryName = category.ProductType,
SKU = product.SKU,
Desc = product.Desc
})
.OrderBy(product => product.ProductName)
.ToList();
}
else if ((viewModel.ProductName == null) && viewModel.CategoryId == 0)
{
items = (from product in db.tblFMSItems
join category in db.FMSCategory on product.CategoryID equals category.ID
where product.CenterID == user.CenterId
select new
{
CategoryId = product.CategoryID,
ProductId = product.ProductId,
ProductName = product.ProductName,
CategoryName = category.ProductType,
SKU = product.SKU,
Desc = product.Desc
})
.OrderBy(product => product.ProductName)
.ToList();
}
var results = new List<VMAddEditProduct>();
foreach (var fmsitem in items)
{
var itemDesc = "";
if (fmsitem.Desc != null && fmsitem.Desc.Contains("<br/>"))
{
itemDesc = fmsitem.Desc.Replace("<br/>", "\n");
}
else
{
itemDesc = fmsitem.Desc;
}
var result = new VMAddEditProduct();
result.CategoryId = fmsitem.CategoryId;
result.CategoryName = fmsitem.CategoryName;
result.ProductId = fmsitem.ProductId;
result.SKU = fmsitem.SKU;
result.ProductName = fmsitem.ProductName;
result.Desc = itemDesc;
results.Add(result);
}
return View("~/Views/Report/AddEditProducts.cshtml", results);
}
我在這里發現錯誤:
<link type="text/css" rel="stylesheet" src="@Url.Content("~/Content/jqtree.css")" />
“ src”導致jqtree.css不被我的頁面使用,因此我將其更改為“ href”,從而解決了該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.