0
我有一些自定義樹節點;劍道treeview和自定義節點
所以
所以我使用jQuery來添加,重命名,刪除一個節點的正常節點樹視圖的功能將無法正常工作(追加,刪除等);
這一切都很好,除了當我添加一個新節點時; 我使用jQuery克隆節點並將新節點添加到樹視圖(我更新節點的所有自定義屬性);
問題:
新克隆的節點的UID相同克隆的節點;我試圖給新的uid添加一個「1」,但它會導致錯誤被左右拋出;我知道這個uid是一個GUID,但是還有更多嗎?場景邏輯背後有一些奇怪的東西阻止我改變節點的uid嗎?
下面是JavaScript示例(這是在對服務器的ajax調用和數據庫更新之後;我不想刷新整個樹;相反,我只是想將節點添加到JavaScript側的樹中):
function AddNew(newlyAddedJob)
{
var newJobId = newlyAddedJob.JobId;
var parentJobId = newlyAddedJob.ParentJobId;
var newJobIdCrums = newlyAddedJob.JobIdCrums;
var parentJobIdCrums = newJobIdCrums.substring(0, newJobIdCrums.indexOf(parentJobId) + parentJobId.toString().length);
var trv = $("#" + trvMonitorListId).data("kendoTreeView");
var jParent = "#" + trvMonitorListId + "> * li[data-jobidcrums='" + parentJobIdCrums + "']";
var jSibiling = "#" + trvMonitorListId + "> * li[data-jobidcrums='" + parentJobIdCrums + "']> ul > li";
var jSelector = jSibiling;
if ($(jSibiling).length < 1)
{
jSelector = jParent;
}
var newUId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c)
{
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
var aNode = $(jSelector)[0];
var newNode = $(aNode).clone();
var origUid = $(jSelector).attr("data-uid");
newNode.attr("id", newJobId);
newNode.attr("data-jobId", newJobId);
newNode.attr("data-parentJobId", parentJobId);
newNode.attr("data-jobIdCrums", newlyAddedJob.JobIdCrums);
newNode.attr("data-uid", newUId);
$(jParent).append(newNode);
var jNewNodeSelector = "#" + trvMonitorListId + "> * li[data-jobidcrums='" + newlyAddedJob.JobIdCrums + "'] > div > * a";
$(jNewNodeSelector)[0].innerText = "Stuff and more ...";
$(jSelector + " * span.k-in.k-state-selected").toggleClass("k-in k-state-selected", "k-in");
//var domText = $(jselector + "di");
trv = $("#" + trvMonitorListId).data("kendoTreeView");
trv.select(newNode);
GetMonitorDetails(newJobId, parentJobId);
}
我更新了我的問題以包含javascript;也更新我的代碼添加一個虛擬GUID,這也不起作用;會發生什麼呢,它說trv.select(newNode)的最後一行會拋出一個錯誤,說「無法獲取屬性'set'」。另外,我認爲新ID會導致我的頁面刷新,這很奇怪,但很有趣:) – DotNet98 2014-10-30 15:43:17