Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在树节点jstree中存储多个值?_Jquery_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Jquery 如何在树节点jstree中存储多个值?

Jquery 如何在树节点jstree中存储多个值?,jquery,asp.net-mvc,asp.net-mvc-4,Jquery,Asp.net Mvc,Asp.net Mvc 4,我将以下属性传递给jstree public class TVCVM { public String id { get; set; } public string @class { get; set; } public string parent { get; set; } public string text { get; set; } public string value { get; set; }

我将以下属性传递给
jstree

public class TVCVM
    {
        public String id { get; set; }
        public string @class { get; set; }
        public string parent { get; set; }
        public string text { get; set; }
        public string value { get; set; }
    }
在操作中,假设我创建了以下数据

 [HttpGet]
        public JsonResult GetData()
        {
            var tvdata = new List<TVCVM>();
            tvdata.Add(new TVCVM { id = "n1", parent = "#", text = "Cardiology", value = "10", @class= "parentNode"});
            tvdata.Add(new TVCVM { id = "n2", parent = "#", text = "Physio", value = "11", @class = "parentNode" });
            tvdata.Add(new TVCVM { id = "n3", parent = "n2", text = "hassan", value = "100", @class = "childNode" });
            tvdata.Add(new TVCVM { id = "n4", parent = "n2", text = "Wick", value = "101", @class = "childNode" });

            return Json(tvdata, JsonRequestBehavior.AllowGet);
        }
通过defualt,文本属性将分配给节点文本,值属性应分配给值。以下代码在js中生成ajax代码:

    $(document).ready(function () {
        $.ajax({
            url: 'Home/GetData',
            method: 'get',
            dataType: 'json',
            success: function (data) {
                $('#Div_jstree').on('select_node.jstree', function (event, data) {
                    console.log( $("#Div_jstree").jstree().get_selected(true)[0].text );
                    console.log(data);
                    var htmlta = '<br><div style="display:inline-block;" ' + 'id=div-' + data.studentid + '>' +
                        '<textarea style=width:100px;height:100px;visibility:visible;' + 'id=' + data.studentid + '>' + $("#Div_jstree").jstree().get_selected(true)[0].text
                         + ':</textarea>' +
                        '<input type="button" class="del" value="Close"' + 'id=' + data.id + ' /></div>';
                    $('#Div_txta').append(htmlta);

                    $(document).on('click', '.del', function () {
                        $(this).closest('div').remove();
                    });
                })
                .jstree({
                    "core": {
                        "data": data,
                        "themes": {
                            "url": true,
                            "icons": true,
                            "dots": true
                        },
                        'check_callback': true
                    },
                    "plugins": ["dnd"]
                });
            },
            error: function (x, y, z) {
                console.log('error');
            }
        });
    });
</script>
$(文档).ready(函数(){
$.ajax({
url:“主页/GetData”,
方法:“get”,
数据类型:“json”,
成功:功能(数据){
$('#Div_jstree')。on('select_node.jstree',函数(事件,数据){
console.log($(“#Div_jstree”).jstree().get_selected(true)[0].text);
控制台日志(数据);
var htmlta='
'+ '+$(“#Div_jstree”).jstree().get_selected(true)[0]。文本 + ':' + ''; $('#Div_txta').append(htmlta); $(文档).on('单击','.del',函数(){ $(this).closest('div').remove(); }); }) jstree先生({ “核心”:{ “数据”:数据, “主题”:{ “url”:正确, “图标”:没错, “点”:真的吗 }, “检查回调”:true }, “插件”:[“dnd”] }); }, 错误:函数(x,y,z){ console.log('error'); } }); });
$('#Div_jstree')。在('select_node.jstree',function(event,data){…}
数据应包含节点数据(即:text/value),但我希望存储所有属性值 来自json
“id、class、parent、text、value”
,如何将所有数据存储在它们的节点中

    $(document).ready(function () {
        $.ajax({
            url: 'Home/GetData',
            method: 'get',
            dataType: 'json',
            success: function (data) {
                $('#Div_jstree').on('select_node.jstree', function (event, data) {
                    console.log( $("#Div_jstree").jstree().get_selected(true)[0].text );
                    console.log(data);
                    var htmlta = '<br><div style="display:inline-block;" ' + 'id=div-' + data.studentid + '>' +
                        '<textarea style=width:100px;height:100px;visibility:visible;' + 'id=' + data.studentid + '>' + $("#Div_jstree").jstree().get_selected(true)[0].text
                         + ':</textarea>' +
                        '<input type="button" class="del" value="Close"' + 'id=' + data.id + ' /></div>';
                    $('#Div_txta').append(htmlta);

                    $(document).on('click', '.del', function () {
                        $(this).closest('div').remove();
                    });
                })
                .jstree({
                    "core": {
                        "data": data,
                        "themes": {
                            "url": true,
                            "icons": true,
                            "dots": true
                        },
                        'check_callback': true
                    },
                    "plugins": ["dnd"]
                });
            },
            error: function (x, y, z) {
                console.log('error');
            }
        });
    });
</script>