它使用带有javascript的ASP.NET MVC在树视图中显示“undefined”

时间:2018-04-23 09:46:15

标签: javascript jquery asp.net-mvc-4

从oracle数据库获取数据时,使用ASP.NET MVC和Gijgo树视图JQuery插件在树视图结构中显示“未定义”,树视图控件可以显示分层(或嵌套或递归)集合可扩展节点树中的数据。如何解决这个问题?。请任何人帮助我。

我正在尝试此链接

https://www.codeproject.com/Articles/1185174/How-to-create-Dynamic-draggable-and-droppable-Tree

output image

@section Scripts {
    @Scripts.Render("~/bundles/Scripts/jqueryval") <script src="~/Scripts/jquery.validate.min.js"></script> <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
    <script src="@Url.Content("~/Scripts/conditional-validation.js")" type="text/javascript"></script>
    <script src="~/Scripts/Gijgo/gijgo.js"></script>
    <link href="http://code.gijgo.com/1.3.0/css/gijgo.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        //'Hierarchy/GetHierarchy'
        $(document).ready(function () {
            var Usertree = "";
            var tree = "";
            $.ajax({
                type: 'get',
                dataType: 'json',
                cache: false,
                url: '/Hierarchy/GetHierarchy',
                success: function (records, textStatus, jqXHR) {
                    tree = $('#tree').tree({
                        primaryKey: 'Id',
                        dataSource: records,
                        dragAndDrop: true,
                        checkboxes: true,
                        iconsLibrary: 'glyphicons',
                        //uiLibrary: 'bootstrap'
                    });
                    Usertree = $('#Usertree').tree({
                        primaryKey: 'ID',
                        dataSource: records,
                        dragAndDrop: false,
                        checkboxes: true,
                        iconsLibrary: 'glyphicons',
                        //uiLibrary: 'bootstrap'
                    });

                    tree.on('nodeDrop', function (e, ID, PID) {
                        currentNode = ID ? tree.getDataById(Id) : {};
                        console.log("current Node = " + currentNode);
                        parentNode = PID ? tree.getDataById(PID) : {};
                        console.log("parent Node = " + parentNode);

                        if (currentNode.PID === null && parentNode.PID === null) {
                            alert("Parent node is not droppable..!!");
                            return false;
                        }
                        // console.log(parent.HierarchyLevel);
                        var params = { id: ID, parentId: PID };
                        $.ajax({
                            type: "POST",
                            url: "/Hierarchy/ChangeNodePosition",
                            data: params,
                            dataType: "json",
                            success: function (data) {
                                $.ajax({
                                    type: "Get",
                                    url: "/Hierarchy/GetHierarchy",
                                    dataType: "json",
                                    success: function (records) {
                                        Usertree.destroy();
                                        Usertree = $('#Usertree').tree({
                                            primaryKey: 'ID',
                                            dataSource: records,
                                            dragAndDrop: false,
                                            checkboxes: true,
                                            iconsLibrary: 'glyphicons',
                                            //uiLibrary: 'bootstrap'
                                        });
                                    }
                                });

                            }
                        });

                    });

                    $('#btnGetValue').click(function (e) {
                        var result = Usertree.getCheckedNodes();
                        if (result == "") { alert("Please Select Node..!!") }
                        else {
                            alert("Selected Node id is= " + result.join());
                        }
                    });
                       //delete node
                    $('#btnDeleteNode').click(function (e) {
                        e.preventDefault();
                        var result = tree.getCheckedNodes();
                        if (result != "") {
                            $.ajax({
                                type: "POST",
                                url: "/Hierarchy/DeleteNode",
                                data: { values: result.toString() },
                                dataType: "json",
                                success: function (data) {
                                    alert("Deleted successfully ");
                                    window.location.reload();
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert('Error - ' + errorThrown);
                                },
                            });
                        }
                        else {
                            alert("Please select Node to delete..!!");
                        }


                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert('Error - ' + errorThrown);
                }
            });

            // show model popup to add new node in Tree
            $('#btnpopoverAddNode').click(function (e) {
                e.preventDefault();
                $("#modalAddNode").modal("show");
            });

            //Save data from PopUp
            $(document).on("click", "#savenode", function (event) {
                event.preventDefault();
                $.validator.unobtrusive.parse($('#formaddNode'));
                $('#formaddNode').validate();
                if ($('#formaddNode').valid()) {
                    var formdata = $('#formaddNode').serialize();
                    // alert(formdata);
                    $.ajax({
                        type: "POST",
                        url: "/Hierarchy/AddNewNode",
                        dataType: "json",
                        data: formdata,
                        success: function (response) {
                            // $("#modalAddNode").modal("hide");
                            window.location.reload();
                        },
                        error: function (response) {
                            alert('Exception found');
                            //  $("#modalAddNode").modal("hide");
                            window.location.reload();
                        },
                        complete: function () {
                            //  $('.ajax-loader').css("visibility", "hidden");
                        }
                    });
                }

            });

            //Close PopUp
            $(document).on("click", "#closePopup", function (e) {
                e.preventDefault();
                $("#modalAddNode").modal("hide");
            });

            $('.rbtnnodetype').click(function (e) {
                if ($(this).val() == "Pn") {
                    $('.petenddiv').attr("class", "petenddiv hidden");

                    $("#ParentName").val("");
                }
                else {
                    $('.petenddiv').attr("class", "petenddiv");
                }
            });

        });

    </script>

}

1 个答案:

答案 0 :(得分:1)

只需确保将属性命名为“text”,包括小写,因为库会将此字段绑定到标签。没有具有此名称的属性会使其未定义。