1
我使用openTemplate函數在#TreeDiv中渲染dynatree樹視圖。之前,我加載所有單位在dynatree一定的模板我空/清除#TreeDiv刪除現有的樹。這是第一次。
當我嘗試加載其他單位另一個模板在#TreeDiv我沒有看到我的單位數據,在div只是空的。不知怎麼的,#TreeDiv被損壞了,因爲代碼像第一次創建單元樹一樣正常運行。不同的是,在第二次我做一個.empty()時,已經存在一棵樹。
什麼我錯了嗎?
function openTemplate(dlg, form) {
$.ajax({
url: $(form).attr('action'),
type: 'POST',
data: form.serialize(),
success: function (response) {
if (response.success) {
dlg.dialog("close");
$('#TreeDiv').empty();
loadUnits(response.data);
}
else {
// Reload the dialog with the form to show model/validation errors
dlg.html(response);
}
}
});
}
function loadUnits(data) {
$('#TreeDiv').dynatree({
onActivate: function (node) {
getTestSteps(node.data.key);
},
onLazyRead: function (node) {
node.appendAjax({
url: '@Url.Action("GetChildrenUnits","Unit")',
data: {"unitId": node.data.key, "templateId": 1 }
});
},
children: data
});
}
如何我可以檢查.empty()函數做了什麼? – Elisabeth
我會一個「嘗試」塊內運行或if語句包裹。你也可以做到超時 – RedMage