Question

J'essaie de construire un Treepanel (ou juste un arbre simple, j'ai juste besoin qu'il fonctionne) et de le charger avec des données de la base de données

Voici mon code pour construire l'arbre

  var objHandler = new Interact();

  var treestore = new  Ext.data.TreeStore ( {

     root:{
            id:'root_node',
            nodeType:'async',
            text:'Root'            
        },
     proxy:{            
            type:'ajax',            
            url:'myUrl'
        }


});     


    function ReadTree() {
            try {
                objHandler.ReadAssets(function (serverResponse) {
                    if (serverResponse.error == null) {
                        var result = serverResponse.result;

                        if (result.length > 2) {
                            treestore.load(Ext.decode(result));//TreeStore does not inherit from Ext.data.Store and thus does not have a loadData method. Both TreeStore and Store inherit from Ext.data.AbstractStore which defines a load method only. Therefore TreeStore has a load method
                           }
                    }
                    else {
                        alert(serverResponse.error.message);
                    }
                }); //eo serverResponse
            } //eo try
            catch (e) {
                alert(e.message);
            }
        }




 var AssetTree = Ext.create('Ext.tree.Panel', {
    title: 'Asset Tree',
    width: 200,
    height: 150,
    store: treestore,
   // loader: new Ext.tree.TreeLoader({    url: 'myurl'  }),

    columns: [
                { xtype: 'treecolumn',text : 'First Name',  dataIndex :'Title'}/*,
                {text : 'Last',  dataIndex :'Adress'},
                {text : 'Hired Month',  dataIndex :'Description'}*/
             ],
    autoscroll : true

}); 

     ReadTree();

Im utilise du jayrock: http://code.google.com/p/jayrock/

Interact.ashx.cs:

classe publique Interact: jsonrpchandler {

    [JsonRpcMethod()]
    public string ReadAssets()
     {
        // Make calls to DB or your custom assembly in project and return the result in JSON format. //This part is making custom assembly calls.

        clsDBInteract objDBInteract = new clsDBInteract();
        string result;
        try
         {
            result = objDBInteract.FetchAssetsJSON();
         }
        catch (Exception ex)
         {
            throw ex;
         }
        return result;

     }

clsdbinteract.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using Extensions;

namespace WebBrowser
{
    public class clsDBInteract
    {

        SqlConnection dbConn = new SqlConnection("server=***********; user id = *****; password = ******; Database=*******");

        /////// data to fill assets grid
        public DataSet FetchAssetsDS()
        {
            DataSet ds = new DataSet();
            try
              {
                SqlCommand sqlCommand = new SqlCommand("select Title, adress, Description from table");
                sqlCommand.Connection = dbConn;
                sqlCommand.CommandType = CommandType.Text;
                SqlDataAdapter sda = new SqlDataAdapter(sqlCommand);
                dbConn.Open();
                sda.Fill(ds);
                if (sqlCommand.Connection.State == ConnectionState.Open)
                    {
                    dbConn.Close();
                    }
                //ds = sqlCommand.ExecuteNonQuery();
              }
           catch (Exception ex)
             {
                 throw ex;
             }
          return ds;
       }//eo FetchAssetsDS

       public string FetchAssetsJSON()
        {
            string result = string.Empty;
            try
               {
                DataSet ds = FetchAssetsDS();
                result = ds.ToJSONString(); // This method will convert the contents on Dataset to JSON format;
               }
            catch (Exception ex)
             {
                 throw ex;
             }
            return result;
        }//eo FetchAssetsJSON




    }//eo clsDBInteract
}

Je n'ai aucune erreur, mais le panneau est vide, j'ai testé et je peux lire les données dans la fonction ReadTree .. donc je suppose que le problème serait peut-être dans le magasin peut-être ou le chargement

Cela fait plus de deux semaines que j'essaie de réaliser cela toute aide serait appréciée

Ps: im utilise extjs4 avec c # .net

Merci

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top