【问题标题】:Trying to use JSONStore in a combo尝试组合使用 JSONStore
【发布时间】:2016-10-11 16:02:28
【问题描述】:

在我们的应用程序中,我们有很多名称/值存储,它们在加载时创建并像这样放入 JSONStore 中:

Ext.create("Ext.data.JsonStore", {
    data: data,
    model: 'EM.model.controlUnit.CodeList',
    storeId: "cl_" + tableId,
    sorters: [{
        sorterFn: aSorterFunction
    }],
});

模型非常简单,看起来像这样:

Ext.define('EM.model.controlUnit.CodeList', {
    extend: 'Ext.data.Model',

    fields: [{
        name: 'value', type: 'int'
    }, {
        name: 'label', type: 'string'
    }, {
        name: 'description', type: 'string'
    }]
});

我认为商店是可以互换的,所以我决定在组合中使用商店(没有特殊的组合商店,所以我认为 JSONStore 必须与 SimpleStore 一样好)。我得到了这样的商店:

var msDataStore = Ext.getStore("cl_t_cl_maritalstatus");

然后像这样使用商店:

{
    xtype: 'combo',
    fieldLabel: 'Marital Status',
    displayField: "label",
    valueField: "value",
    store: msDataStore
}

当我运行应用程序时,组合中填充了来自商店的值,但是,当我弹出组合框时,会抛出此错误:

ext-debug-w-cmets.js:9951 未捕获 Ext.data.proxy.Server.buildUrl():您正在使用 ServerProxy 但有 没有提供网址。

我不想要任何服务器代理。这些是简单的本地存储名称值集合。

  • JSONStore 可以与组合一起使用吗?
  • 如果没有。将 JSONStore 转换为组合可接受的东西的最佳方法是什么。我可以切碎、更改、重组存储对象。但我只是想知道在进行某种漫长而毫无意义的旅程之前,我是否可以做一些更简单的事情。

【问题讨论】:

    标签: extjs combobox extjs4


    【解决方案1】:

    此问题与“代理”属性有关。 JsonStore 的默认代理是 'ajax';

    代理: { 类型:'ajax', 读者:'json', 作家:'json' }

    你应该像那样用“内存”覆盖;

    代理: { 类型:“记忆” }

    您的最终商店是;

    Ext.create("Ext.data.JsonStore", {
        data: data,
        model: 'EM.model.controlUnit.CodeList',
        storeId: "cl_" + tableId,
        proxy: {
            type: 'memory'
        }
        sorters: [{
            sorterFn: aSorterFunction
        }],
    });
    

    【讨论】:

      【解决方案2】:

      没有 URL 的 JsonStore 是完全可以接受的,但您必须确保在单击下拉列表时组合不会触发加载操作。这是通过将配置选项 queryMode:'local' 添加到组合定义中来完成的:

      {
          xtype: 'combo',
          fieldLabel: 'Marital Status',
          displayField: "label",
          valueField: "value",
          queryMode: 'local',
          store: msDataStore
      }
      

      【讨论】:

        猜你喜欢
        • 2011-08-28
        • 2011-09-04
        • 1970-01-01
        • 2011-02-20
        • 2013-01-13
        • 2012-11-05
        • 2017-06-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多