开发者

Build and load a tree with data from database with ExtJs

I'm trying to build a treepanel (or just a simple tree I just need it to work) and load it with data from database

I've been trying and trying and trying ..but cant do it.

Can someone show me how can I do this please?

My JSON:

{ 
    {Title:'yahoo Website',adress:'www.yahoo.com',Description:'Serveur yaho开发者_C百科o'}, 
    {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--'} 
]

My C# code:

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; 
}


firstly look at this simple example. This tree have a store wich can read infromation from url by json scructure. You can write there http://youdomain.com/yourscript.php. At yourscript.php you have to read information from database, encode it to JSON and run echo your_json; That's all. P.S. json example


i solved this by creating my own type (no jayrock)

my tree model and store:

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'
}]
});

my class:

   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; }

}

then i get my data and fill my tree like this

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 };
}

hope it helps someone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜