EXTJS网格存储加载 - 添加参数?

时间:2013-06-12 20:20:30

标签: web-services extjs parameter-passing

我正在将asp转发器转换为EXTJS网格。转发器上方是下拉列表和单选按钮列表。下拉列表选择哪些客户端'转发器显示的数据,radiobuttonlist选择查询类型(默认,资源或角色)。目前,当更改ddl或radiobutton时,页面将使用新数据进行回发。

我不确定如何通过extjs store api GET调用将这两个对象的值传递到后端的静态Web服务中。

extjs存储代码......

store: Ext.create('Ext.data.Store', {
                    autoLoad: true,
                    autoSync: false,
                    model: 'Assembly',
                    proxy: {
                        type: 'ajax',
                        headers: { "Content-Type": 'application/json' },
                        api: {
                            read: '/Admin/BillRateData.aspx/Get'
                        },
                        reader: {
                            type: 'json',
                            root: function (o) {
                                if (o.d) {
                                    return o.d;
                                } else {
                                    return o.children;
                                }
                            }
                        },
                        writer: {
                            type: 'json',
                            root: 'jsonData',
                            encode: false,
                            allowSingle: false
                        },
                        listeners: {
                            exception: function (proxy, response, operation) {
                                Ext.MessageBox.show({
                                    title: "Workflow Groups Error",
                                    msg: operation.action + ' Operation Failed: ' + operation.getError().statusText,
                                    icon: Ext.MessageBox.ERROR,
                                    buttons: Ext.Msg.OK
                                });
                            }
                        }
                    }

和webservice ...(带有一些伪代码)

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
    public static List<BillRate> Get()
    {
        using (TimEntities db = new TimEntities())
        {
            int tableId = Int32.Parse(ddlTable.SelectedValue);

            var defaultQry = from t1 in db.BillCostTableDatas
                             where t1.TableId == tableId
                             && t1.ResourceId == 0 && t1.RoleId == 0
                             orderby t1.Rate
                             select new
                             {
                                 id = t1.Id,
                                 resource = "",
                                 role = "",
                                 rate = t1.Rate,
                                 TierName = ""
                             };

            var resourceQry = from t1 in db.BillCostTableDatas
                              join t2 in db.Machines on t1.ResourceId equals t2.Machine_ID
                              join t3 in db.TOMIS_USER on t2.Machine_User_ID equals t3.User_ID
                              join t4 in db.PricingTierNames on t1.PricingTierID equals t4.TierID
                              where t1.TableId == tableId
                                && t1.ResourceId != 0
                                && t1.RoleId == 0
                              orderby t3.LName, t3.FName, t1.Rate, t4.TierName
                              select new
                              {
                                  id = t1.Id,
                                  resource = t3.LName + ", " + t3.FName,
                                  role = "",
                                  rate = t1.Rate,
                                  TierName = t4.TierName
                              };

            var roleQry = from t1 in db.BillCostTableDatas
                          join t2 in db.TaskRoles on t1.RoleId equals t2.Id
                          where t1.TableId == tableId
                          && t1.ResourceId == 2 && t1.RoleId != 0
                          orderby t2.Name, t1.Rate
                          select new
                          {
                              id = t1.Id,
                              resource = "",
                              role = t2.Name,
                              rate = t1.Rate,
                              TierName = ""
                          };

            if (this.rblOptions.SelectedValue == "resource")
            {
                var results = from Res in resourceQry.ToList()
                              select new BillRate
                              {

                              };
                return results.ToList();
            }
            else if (this.rblOptions.SelectedValue == "role")
            {
                var results = from Res in roleQry.ToList()
                              select new BillRate
                              {

                              };
                return results.ToList();
            }
            else
            {
                var results = from Res in defaultQry.ToList()
                              select new BillRate
                              {

                              };
                return results.ToList();
            }

            return null;
        }
    }

1 个答案:

答案 0 :(得分:7)

如果您手动触发商店加载,则可以将params选项传递给load method

示例:

var store = Ext.create('Ext.data.Store', {
    // prevent the store from loading before we told it to do so
    autoLoad: false
    ...
});

store.load({
    params: {clientId: 123, queryType: 'default'}
    ...
});

如果您希望为多个后续查询发送参数,则可以将其写入代理的extraParams属性中。

示例:

var store = Ext.create('Ext.data.Store', { ... });

Ext.apply(store.getProxy().extraParams, {
    clientId: 321
    ,queryType: 'role'
});

// the store will still need a refresh
store.reload();

这些参数传递给服务器的方式取决于请求的类型。对于GET,它们将作为查询参数附加;对于POST,它们将嵌入请求正文中。