提问人:Lewis Boxer 提问时间:6/19/2023 更新时间:6/19/2023 访问量:54
FancyTree 选择从 AJAX 数据填充表单
FancyTree select to populate form from AJAX data
问:
我已经实现了fancyTree,它从JSON数据中填充自身,
我正在尝试构建它,以便当在fancyTree中选择文件时,会从其余的JSON数据中自动填充HTML表单,
但我无法让它工作
HTML 表单:
<div id="filter-form">
<label for="filter-input">Filter:</label>
<input type="text" id="filter-input" />
</div>
<div id="tree" style="width: 400px; height: 500px;"></div>
<div id="drawingDetails">
<form>
<label for="Area">Area:</label>
<input id="Area" name="Area">
<label for="Category">Drawing Category:</label>
<input id="Category" name="Category">
<label for="Drawing_Number">Drawing Number:</label>
<input id="Drawing_Number" name="Drawing_Number">
<label for="Drawing_Sheet">Drawing Sheet:</label>
<input id="Drawing_Sheet" name="Drawing_Sheet">
<label for="Drawing_Rev">Drawing Rev:</label>
<input id="Drawing_Rev" name="Drawing_Rev">
<label for="DrawingDate">Drawing Revision Date:</label>
<input id="DrawingDate" name="DrawingDate">
<label for="DrawingDesc">Drawing Description:</label>
<input id="DrawingDesc" name="DrawingDesc">
<label for="Status">Drawing Status:</label>
<input id="Status" name="Status">
</form>
</div>
// Event handler for populating the form when selecting a file
select: function (event, data) {
var node = data.node;
var nodeData = node.data || {}; // Initialize nodeData as an empty object
if (node.isFolder()) {
console.log("Folder Selected");
// If a folder node is selected, clear the form fields
$("#Area").val("");
$("#Category").val("");
$("#Drawing_Number").val("");
$("#Drawing_Sheet").val("");
$("#Drawing_Rev").val("");
$("#DrawingDate").val("");
$("#DrawingDesc").val("");
$("#Status").val("");
} else {
console.log("Selected Node Data:", nodeData);
// Populate the form with the node data
$("#Area").val(nodeData.Area_Name);
$("#Category").val(nodeData.Category_Name);
$("#Drawing_Number").val(nodeData.Drawing_Number);
$("#Drawing_Sheet").val(nodeData.Drawing_Sheet);
$("#Drawing_Rev").val(nodeData.Revision_Number);
$("#DrawingDate").val(nodeData.Revision_Date);
$("#DrawingDesc").val(nodeData.Revision_Description);
$("#Status").val(nodeData.Status_Code);
}
// Display the form field values
console.log("Area:", $("#Area").val());
console.log("Category:", $("#Category").val());
console.log("Drawing Number:", $("#Drawing_Number").val());
console.log("Drawing Sheet:", $("#Drawing_Sheet").val());
console.log("Drawing Rev:", $("#Drawing_Rev").val());
console.log("Drawing Date:", $("#DrawingDate").val());
console.log("Drawing Description:", $("#DrawingDesc").val());
console.log("Status:", $("#Status").val());
// Add a debugger statement to pause the execution and inspect the variables
debugger;
},
// ... other options and event handlers ...
});
// Fetch data from the server
$.ajax({
url: "/your-server-endpoint",
method: "GET",
dataType: "json",
success: function (data) {
var treeData = processSQLResult(data);
// Update the FancyTree source after fetching the data
console.log(treeData); // Add this line to check the treeData
$("#tree").fancytree("option", "source", treeData);
},
error: function (xhr, status, error) {
console.error("Failed to fetch data from the server:", error);
},
});
fancyTree工作正常,但由于某些原因,选择文件甚至不会显示控制台.log
答: 暂无答案
评论