在表单中加载多个extjs组合框

时间:2012-10-19 12:55:39

标签: extjs

另一个ComboBox问题。

在我的表中,大约有10个字段是外键,都带有组合框。 如何在一个表单中填写所有这些组合,而不是去服务器加载每个组合的商店?

3 个答案:

答案 0 :(得分:2)

它们是作为单独的表存储在后端吗?如果是,那么正确的方法是将它们分别加载到服务器10 。您可以通过以下方式优化此方案:

  • 同时加载所有内容
  • 在您提前到达该页面之前加载所有内容

但是你仍然想在你的ExtJs应用程序中拥有10个不同的商店。

如果您希望将它们组合成单个商店,请记住一些事情

  • 您需要在此组合表中添加其他字段,以便区分不同的列表。
  • 您可以一次加载所有内容
  • 然后你仍然需要将它们分成不同的商店对象,因为否则不同的UI组件(组合框)将无法显示不同的数据集

答案 1 :(得分:1)

众所周知的问题:)通常当我有这样的结构时

var data = {
    ForeignKeyObjectId: 123,
    ForeignKeyObject: {
        Id: 123,
        SomeValue: 'Some text 1'
    },

    SomeOtherObjectId: 456,
    SomeOtherObject: {
        Id: 456,
        SomeValue: 'Some text 2'
    }
    //, ... same 8 times more
}

我必须手动加载每个组合:

var combo1 = this.down('#foreignKeyObjectCombo');
combo1.setValue(data.ForeignKeyObject.Id);
combo1.setRawValue(data.ForeignKeyObject.SomeValue);
combo1.store.loadData([data.ForeignKeyObject], true);

var combo2 = this.down('#someOtherObjectCombo');
combo2.setValue(data.SomeOtherObject.Id);
combo2.setRawValue(data.SomeOtherObject.SomeValue);
combo2.store.loadData([data.SomeOtherObject], true);

// same 8 times more

在我以前关于ExtJs 3的一个项目中,我对form和combobox行为进行了一些覆盖,这样我就可以使用form.getForm().loadData(data)一次而不是像本例中那样手动设置value,rawValue。但这种方式是隐含的,所以我更喜欢这种方式:)

答案 2 :(得分:0)

示例:

模型1

Ext.create('Ext.data.Store', {
        model: 'EmployeeType',
        data : [
            {type: 1,    description: 'Administrative'},
            {type: 2,    description: 'Operative'},
        ]
    });

模型2

Ext.create('Ext.data.Store', {
    model: 'BloodType',
    data : [
        {type: 1,    description: 'A+'},
        {type: 2,    description: 'B+'},
    ]
});

即使你的商店有代理,也可以禁用AutoLoad,这样你就可以在一个单一的请求中加载任意数量的内容,如下所示:

手动创建商店:

employeeType = Ext.create('Ext.data.Store', {model: EmployeeType});
bloodType = Ext.create('Ext.data.Store', {model: BloddType});

创建一个Ajax请求,您可以在其中同时显示所有组合:

Ext.ajax.request({
    url: './catalogs/getalldata',
    success: function(response) {
        var json = Ext.decode(response.responseText);
        employeeType.loadData(json.employeeTypes);
        bloodType.loadData(json.bloodTypes);
        //...
    } 
});
相关问题