TreeView创建:
function CreateNotificationTree(userId)
{
debugger;
var data = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "../api/notifications/byuserid/" + userId,
contentType: "application/json"
}
},
schema: {
model: {
children: "notifications"
}
}
});
$("#treeview").kendoTreeView({
dataSource: data,
loadOnDemand: true,
dataUrlField: "LinksTo",
checkboxes: {
checkChildren: true
},
dataTextField: ["notificationType", "NotificationDesc"],
select: treeviewSelect
});
function treeviewSelect(e)
{
var node = this.dataItem(e.node);
window.open(node.NotificationLink, "_self");
}
}
更新的地方,我需要刷新数据集:
$('#btnDelete').on('click', function()
{
var treeView = $("#treeview").data("kendoTreeView");
var userId = $('#user_id').val();
$('#treeview').find('input:checkbox:checked').each(function()
{
debugger;
var li = $(this).closest(".k-item")[0];
var notificationId = treeView.dataSource.getByUid(li.getAttribute('data-uid')).ID;
if (notificationId == "undefined")
{
alert('No ID was found for one or more notifications selected. These notifications will not be deleted. Please contact IT about this issue.');
}
else
{
$.ajax(
{
url: '../api/notifications/deleteNotification?userId=' + userId + '¬ificationId=' + notificationId,
type: 'DELETE',
success: function()
{
alert('Delete successful.');
//Here is where I try to refresh the data source.
CreateNotificationTree(userId);
},
failure: function()
{
alert('Delete failed.');
}
});
treeView.remove($(this).closest('.k-item'));
}
});
});
这里的问题是它确实刷新了树视图。。。。但不是CHILDREN节点。。。
有人知道怎么做吗?
看起来您正在完全重建树视图。为什么不刷新树视图的数据源?
考虑到你上面的代码,我推荐这个:
treeView.dataSource.read();
此外,根据您从哪种类型的服务器获取JSON,它可能允许浏览器缓存结果,因为Kendo数据源默认使用GET语句。这可以在服务器端修复,也可以切换到使用POST来检索数据:
read: {
url: "../api/notifications/byuserid/" + userId,
contentType: "application/json",
type: "POST" // Fixes issue if browser was caching GET requests
}