【问题标题】:EXTJS grid store load - adding parameters?EXTJS 网格存储加载 - 添加参数?
【发布时间】:2013-06-12 20:20:29
【问题描述】:

我正在将 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;
        }
    }

【问题讨论】:

  • 我不确定我明白你在问什么。如何使用 Ext store 将参数发送到服务器?
  • 网格充满了 js“读取:'/Admin/BillRateData.aspx/Get'”,它调用了我粘贴的 webmethod。我想弄清楚的是如何使用下拉列表和单选按钮列表的值向 GET 调用添加参数,以便 webmethod 可以知道要使用什么查询。

标签: web-services extjs parameter-passing


【解决方案1】:

如果您手动触发商店加载,您可以将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,它们将嵌入到请求正文中。

【讨论】:

    猜你喜欢
    • 2012-04-29
    • 2015-08-18
    • 2012-05-19
    • 1970-01-01
    • 2014-01-04
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    相关资源
    最近更新 更多