树网格ajax不会在extjs中刷新

时间:2012-12-04 12:33:49

标签: ajax extjs

我一直致力于一个项目,我使用extjs来显示一些服务计划。我能够在一开始就填充它。然后我想要一个按钮点击,在网格中填充新数据。 我能够在树服务中成功调用该函数,但不显示数据。 我的treegrid按钮代码是:

{
                xtype: 'button',
                text: 'Search',
                listeners: {
                    click: function () {
                      //  Ext.getCmp('tree').getView().refresh();
                        Ext.Ajax.request({
                            method: 'GET',
                            extend: 'Ext.data.Model',
                            fields: ['planid', 'id', 'text', 'startdate', 'enddate', 'iconCls', 'expanded', 'leaf'],
                            params: {
                                serviceplanid: serviceplanid,
                                userid: userid,
                                // startdate: startdate,
                                // stopdate: stopdate,
                                initialstate: initialstate,
                                fonttype: fonttype,
                                fonttypeex: fonttypeex
                            },
                            url : '/BloomMatrix2/TreeService2.svc/getfulldata',
        reader: new Ext.ux.aspNetJsonReader({ root: 'children'
        }),

        success: function (response) {
                                //console.log(response);
                                //swapStrore();
                            }
                        });
                    }                       
                }
            },

我的服务读取功能:

[WebGet()]
[OperationContract]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public string getdata(String serviceplanid,String userid, String initialstate,String fonttype, String fonttypeex)
 {

    System.Diagnostics.Debug.WriteLine("IN GETDATA"+initialstate);
    SqlConnection Conn = new SqlConnection(CommonFunctions.GetConnectionString("YourConnection"));
    Conn.Open();

    SqlCommand cmd = new SqlCommand("[dbo].[VMResults_GetCategoriesTree]", Conn);
    cmd.Parameters.Add("@UserId", SqlDbType.BigInt).Value = 1;
    cmd.Parameters.Add("@ServicePlanCurrent", SqlDbType.Char).Value = "N";

    cmd.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    DataSet ds1 = new DataSet();
    adapter.Fill(ds1);
    String ret=makeJSON(ds1,initialstate,fonttype,fonttypeex);
    return ret;
}

[WebGet()]
[OperationContract]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string getfulldata(String serviceplanid, String userid, String initialstate, String fonttype, String fonttypeex)
{

    System.Diagnostics.Debug.WriteLine("IN GETDATA" + initialstate);
    SqlConnection Conn = new SqlConnection(CommonFunctions.GetConnectionString("YourConnection"));
    Conn.Open();

    SqlCommand cmd = new SqlCommand("[dbo].[VMResults_GetCategoriesTree]", Conn);
    cmd.Parameters.Add("@UserId", SqlDbType.BigInt).Value = 1;
    cmd.Parameters.Add("@ServicePlanCurrent", SqlDbType.Char).Value = "Y";

    cmd.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    adapter.Fill(ds);
    String ret = makeJSON(ds, initialstate, fonttype, fonttypeex);
    return ret;
}

我必须打电话给后者点击按钮..提前谢谢

1 个答案:

答案 0 :(得分:0)

您需要在树上使用与服务器通信的代理进行商店定义。参见Sencha示例。

或者,如果您想要在代码中运行自己的AJAX请求,而不是在成功块中手动解析的数据中创建NodeInterface个对象,并将它们逐个添加到树面板中 - 不会很漂亮。