1

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

我不确定如何通过 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
                                });
                            }
                        }
                    }

还有网络服务......(带有一些伪代码)

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

1 回答 1

8

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

例子:

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,它们将嵌入到请求正文中。

于 2013-06-13T12:31:58.143 回答