首页 新闻 会员 周边

EasyUi树形下拉列表框 绑定数据所需的Json 格式的数据 需要什么格式? 求大神赐教,在线等

0
悬赏园豆:30 [已解决问题] 解决于 2016-08-01 09:46
 
  1. $('#cc').combotree({   
  2.     url: '/Home/Index',   //这里需要返回什么格式的数据?
  3.     required: true  
  4. });  
小熊vs的主页 小熊vs | 初学一级 | 园豆:20
提问于:2016-07-27 09:07
< >
分享
最佳答案
0

官网上不是有的吗?

http://www.jeasyui.com/documentation/combotree.php

是个数组

收获园豆:30
clarlespeng | 菜鸟二级 |园豆:469 | 2016-07-27 09:20
<input id="cc" value="01"> 

//js
  $('#cc').combotree({
                    url: 'Log/Demo',
                    required: true
                });


控制器方法 

public string Demo()
        {
            return @"[{'id':1,'text':'My Documents',
    'children':[{
        'id':11,
        'text':'Photos',
        'state':'closed',
        'children':[{
            'id':111,
            'text':'Friend'
        },{
            'id':112,
            'text':'Wife'
        },{
            'id':113,
            'text':'Company'
        }]
    },{
        'id':12,
        'text':'Program Files',
        'children':[{
            'id':121,
            'text':'Intel'
        },{
            'id':122,
            'text':'Java',
            'attributes':{
                'p1':'Custom Attribute1',
                'p2':'Custom Attribute2'
            }
        },{
            'id':123,
            'text':'Microsoft Office'
        },{
            'id':124,
            'text':'Games',
            'checked':true
        }]
    },{
        'id':13,
        'text':'index.html'
    },{
        'id':14,
        'text':'about.html'
    },{
        'id':15,
        'text':'welcome.html'
    }]
}]";
            
        }

大哥 知道为什么这样无效吗

小熊vs | 园豆:20 (初学一级) | 2016-07-27 09:33

@小熊vs: 应该是直接返回字符串不认吧 

帮你试了一下,下面这样是可以的

 1 public ActionResult GetTreeDate()
 2         {
 3             string json = @"[{'id':1,'text':'My Documents',
 4                     'children':[{
 5                         'id':11,
 6                         'text':'Photos',
 7                         'state':'closed',
 8                         'children':[{
 9                             'id':111,
10                             'text':'Friend'
11                         },{
12                             'id':112,
13                             'text':'Wife'
14                         },{
15                             'id':113,
16                             'text':'Company'
17                         }]
18                     },{
19                         'id':12,
20                         'text':'Program Files',
21                         'children':[{
22                             'id':121,
23                             'text':'Intel'
24                         },{
25                             'id':122,
26                             'text':'Java',
27                             'attributes':{
28                                 'p1':'Custom Attribute1',
29                                 'p2':'Custom Attribute2'
30                             }
31                         },{
32                             'id':123,
33                             'text':'Microsoft Office'
34                         },{
35                             'id':124,
36                             'text':'Games',
37                             'checked':true
38                         }]
39                     },{
40                         'id':13,
41                         'text':'index.html'
42                     },{
43                         'id':14,
44                         'text':'about.html'
45                     },{
46                         'id':15,
47                         'text':'welcome.html'
48                     }]
49                 }]";
50             var jsonobj = JsonConvert.DeserializeObject<List<TreeNode>>(json);
51             return Json(jsonobj, JsonRequestBehavior.AllowGet);
52         }
53         public class TreeNode
54         {
55             public string id { get; set; }
56             public string text { get; set; }
57             public string state { get; set; }
58             [JsonProperty(PropertyName = "checked")]
59             public bool @checked { get; set; }
60             public Dictionary<string,string> attributes{get;set;}
61             public List<TreeNode> children { get; set; }
62         }
clarlespeng | 园豆:469 (菜鸟二级) | 2016-07-27 10:42

@clarlespeng: 大哥 感谢了

小熊vs | 园豆:20 (初学一级) | 2016-07-30 11:08
其他回答(3)
0

 这东西文档上都会有介绍的吧...

http://www.jeasyui.net/demo/tree_data1.json

大杯美式不加糖不加奶 | 园豆:994 (小虾三级) | 2016-07-27 09:14
<input id="cc" value="01"> 

//js
  $('#cc').combotree({
                    url: 'Log/Demo',
                    required: true
                });


控制器方法 

public string Demo()
        {
            return @"[{'id':1,'text':'My Documents',
    'children':[{
        'id':11,
        'text':'Photos',
        'state':'closed',
        'children':[{
            'id':111,
            'text':'Friend'
        },{
            'id':112,
            'text':'Wife'
        },{
            'id':113,
            'text':'Company'
        }]
    },{
        'id':12,
        'text':'Program Files',
        'children':[{
            'id':121,
            'text':'Intel'
        },{
            'id':122,
            'text':'Java',
            'attributes':{
                'p1':'Custom Attribute1',
                'p2':'Custom Attribute2'
            }
        },{
            'id':123,
            'text':'Microsoft Office'
        },{
            'id':124,
            'text':'Games',
            'checked':true
        }]
    },{
        'id':13,
        'text':'index.html'
    },{
        'id':14,
        'text':'about.html'
    },{
        'id':15,
        'text':'welcome.html'
    }]
}]";
            
        }

这样无效  大哥 知道是什么原因吗

支持(0) 反对(0) 小熊vs | 园豆:20 (初学一级) | 2016-07-27 09:33

@小熊vs: 接收的是个json格式的数据  控制器返回JsonResult

@浮云也是种寂寞: 感谢

支持(0) 反对(0) 小熊vs | 园豆:20 (初学一级) | 2016-07-30 11:09
0

http://www.jeasyui.net/plugins/170.html

 

至于你的JSON为啥不行,因为你JSON不合法啊,JSON必须是双引号

之奇一昂 | 园豆:1421 (小虾三级) | 2016-07-27 09:45

            return "[{\"id\":1,\"text\":\"My Documents\"}]"; //大哥 我返回这个格式的还是不行啊

支持(0) 反对(0) 小熊vs | 园豆:20 (初学一级) | 2016-07-27 09:56

@小熊vs: 你可以先直接在HTML里面声明DATA,看看会不会出问题,如果没问题,那说明你服务器端的问题了,再用浏览器看一个网络请求返回的数据具体是什么样的

支持(0) 反对(0) 之奇一昂 | 园豆:1421 (小虾三级) | 2016-07-27 11:43
0
public JsonResult Demo() 
{
    return Json(json);
}

用JsonResult   

liuxb1991 | 园豆:661 (小虾三级) | 2016-07-27 11:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册