FineUI 官方论坛
标题:
FineUI Tree 插件
[打印本页]
作者:
棕榈
时间:
2020-1-17 14:40
标题:
FineUI Tree 插件
本帖最后由 棕榈 于 2020-1-17 14:40 编辑
FineUI Tree 插件
[attach]12201[/attach]
[attach]12202[/attach]
这是对之前发布Tree插件的一次重构,同时修复了一些错误,如父节点可以拖动到子节点,虽然FineUI给阻止了,但 afterDrop 被执行了。这次增加了编辑功能,文本框的大小会根据内容的变化而改变,回车键确认编辑,ESC键取消编辑,节点的文本为空时或在 afterEdit 返回不允许编辑时会弹出错误提示。
具体使用细节,可以参考示例代码
代码:
@page
@model FineUICore.EmptyProject.RazorPages.Pages.HelloModel
@{
ViewBag.Title = "Hello";
var F = @Html.F();
}
@section body {
<f:Tree ID="Tree1" IsFluid="true" CssClass="blockpanel" ShowHeader="true" Title="树控件(内联)" EnableCollapse="false" SelectedNodeID="zhumadian">
<Nodes>
<f:TreeNode Text="中国" Expanded="true" NodeID="china">
<f:TreeNode Text="河南省" Expanded="true" NodeID="henan">
<f:TreeNode Text="驻马店市" NodeID="zhumadian">
<f:TreeNode Text="遂平县" Leaf="false" NodeID="suiping">
<f:TreeNode Text="槐树乡" Leaf="false" NodeID="huaishu">
<f:TreeNode Text="陈庄村" NodeID="chenzhuang">
</f:TreeNode>
</f:TreeNode>
</f:TreeNode>
</f:TreeNode>
<f:TreeNode Text="漯河市" NodeID="luohe" />
</f:TreeNode>
<f:TreeNode Text="安徽省" Expanded="true" NodeID="anhui">
<f:TreeNode Text="合肥市" Expanded="true" NodeID="hefei">
<f:TreeNode Text="金色池塘小区" NodeID="golden">
</f:TreeNode>
<f:TreeNode Text="中国科学技术大学" NodeID="ustc">
</f:TreeNode>
</f:TreeNode>
</f:TreeNode>
</f:TreeNode>
</Nodes>
</f:Tree>
<f:Button Text="编辑选择中的节点" ID="btnHello" OnClientClick="editSelectedNode()"></f:Button>
}
@section script {
<script src="~/res/js/fineui-tree-plugin.js"></script>
<script>
var tree = null;
const beforeDrop = function (droppedData) {
if (droppedData.dragNodeId === 'zhumadian' && droppedData.targetNodeId === 'hefei') {
if (droppedData.position === 'before') {
return true;
} else {
return false; // 返回 false 表示不允许放置
}
}
return true;
};
const afterDrop = function (droppedData) {
console.log(droppedData.dragNodeId + "," + droppedData.targetNodeId + "," + droppedData.position);
}
const beforeEdit = function (nodeId) {
if (nodeId === 'ustc') {
alert('不允许编辑 ' + F.ui.Tree1.getNodeData(nodeId).text);
return false; // 返回 false 表示不允许编辑
}
return true;
}
const afterEdit = function (nodeId, nodeText, oldNodeText) {
if (nodeId === 'golden') {
if (nodeText.indexOf('小区') === -1) {
return '必须包含 小区'; // 返回文本表示编辑不成功,同时会显示错误提示
}
}
if (nodeId === 'luohe') {
if (nodeText.indexOf('漯河') === -1) {
return false; // 返回 false 表示编辑不成功,不会显示错误提示
}
}
if (nodeText === oldNodeText) {
console.log('节点文本未被更改');
}
return true;
}
const editSelectedNode = function () {
if (tree) {
tree.editNode(F.ui.Tree1.getSelectedNode());
}
}
F.ready(function () {
tree = F.ext.treePlugin({
treeId: 'Tree1',
enableDragDrop: true,
beforeDrop: beforeDrop,
afterDrop: afterDrop,
beforeEdit: beforeEdit,
afterEdit: afterEdit
});
});
</script>
}
复制代码
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4