0

我正在尝试构建一个树形面板(或者只是一个我只需要它工作的简单树)并使用数据库中的数据加载它

我一直在尝试,尝试和尝试..但做不到。

有人可以告诉我我该怎么做吗?

我的 JSON:

{ 
    {Title:'yahoo Website',adress:'www.yahoo.com',Description:'Serveur yahoo'}, 
    {Title:'skype',adress:'skype.com',Description:'skype.com'},
    {Title:'bing',adress:'www.bing.com',Description:'microsoft bing'},
    {Title:'facebook',adress:'www.facebook.com',Description:'social network'},
    {Title:'Google',adress:'Google.com',Description:'Google';},
    {Title:'\' or 1=1--',adress:'\' or 1=1--',Description:'\' or 1=1--'} 
]

我的 C# 代码:

public class Interact : JsonRpcHandler {
    [JsonRpcMethod()]
    public string ReadAssets() { 
        clsDBInteract objDBInteract = new clsDBInteract(); 
        string result;
         try {
             result = objDBInteract.FetchAssetsJSON(); 
        } catch (Exception ex) {
             throw ex;
        }
     return result; 
}
4

2 回答 2

1

首先看这个简单的例子。这棵树有一个商店,可以通过 json 结构从 url 读取信息。你可以在那里写http://youdomain.com/yourscript.php。在 yourscript.php 中,您必须从数据库中读取信息,将其编码为 JSON 并运行,仅此而已echo your_json; 。PS json 示例

于 2011-05-18T08:44:30.637 回答
0

我通过创建自己的类型解决了这个问题(没有 jayrock)

我的树模型和商店:

Ext.define('TreeModel', {
extend: 'Ext.data.Model',
fields: [
        { name: 'text' },
        { name: 'id' },
        { name: 'descr' }

    ]
});

window.TreeStore = Ext.create('Ext.data.TreeStore', {
model: 'TreeModel',
root: Ext.decode(obj.TreeToJson()),
proxy: {
    type: 'ajax'
},
sorters: [{
    property: 'leaf',
    direction: 'ASC'
}, {
    property: 'text',
    direction: 'ASC'
}]
});

我的课:

   public class TreeItem
{
    public string text { get; set; }

    public int id { get; set; }

    public string descr { get; set; }

    public string expanded { get; set; }

    public string leaf { get; set; }

    public List<TreeItem> children { get; set; }

}

然后我得到我的数据并像这样填充我的树

public string TreeToJson()
    {  
List<TreeItem> child = new List<TreeItem>();
        for (int i = 0; i < n; i++)
        {
            child.Add(new TreeItem() { text = t.AssetTree()[i].Item1, id = t.AssetTree()[i].Item2, ip = t.AssetTree()[i].Item3, descr = t.AssetTree()[i].Item4, expanded = "false", leaf = "true" });
        }

        TreeItem tree = new TreeItem() { text = "my root", id = 0, expanded = "true", leaf = "false", children = child };
}

希望它可以帮助某人

于 2011-10-28T16:17:52.670 回答