【问题标题】:ExtJS 5.1: Setting default ComboBox value using MVVM storeExtJS 5.1:使用 MVVM 存储设置默认 ComboBox 值
【发布时间】:2015-07-09 05:45:30
【问题描述】:

在我的 ViewModel 中,我为我在视图中绑定到的 ComboBox 创建了一个内联数据存储。我遇到的问题是根据商店中的一个值为 ComboBox 设置默认值...我可能在这里理解绑定,所以我想听听任何反馈。

OrderDetailsS​​tatus 模型:

Ext.define('UserUI.model.OrderDetailsStatus', {
    extend: 'Ext.data.Model',
    alias: 'model.OrderDetailsStatus',

    fields: [{
        type: 'int',
        name: 'statusId'
    },
    {
        type: 'string',
        name: 'status'
    }]
});

视图模型:

stores: {
        /* TODO: This could eventually become an AJAX call, but for right now,
         * it's an inline data store... the statusId's are currently unused */
        orderDetailsStatusStore: {
            model: 'UserUI.model.OrderDetailsStatus',
            proxy: {
                type: 'memory'
            },
            data: [
                { status: 'All', statusId: 1 },
                { status: 'Correct', statusId: 2 },
                { status: 'Incorrect', statusId: 3 }
            ]
        }
    }

在视图中:

{
                xtype: 'combo',
                fieldLabel: 'Status',
                bind: {
                    store: '{orderDetailsStatusStore}'
                },
                valueField: 'status',
                displayField: 'status',
                queryMode: 'local',
                value: 'All',
                listeners: {
                    select: 'onSelectComboBoxStatus'
                }
            }

使用值:'All' 给我一个关于模型不存在的错误:

TypeError: Model is not a constructor: ext-all...ebug.js (line 122343, col 33)
    record = new Model(dataObj);

我假设这是因为绑定的商店尚未完全加载?如果我在该行调试代码,模型是未定义的,并且商店没有任何数据。任何帮助将不胜感激。

【问题讨论】:

    标签: extjs combobox extjs5


    【解决方案1】:

    在 5.1.0 中更新了 Fiddle

    <iframe src="https://fiddle.sencha.com/fiddle/m3g"></iframe>

    我创建了一个简单的小提琴来复制你的 - https://fiddle.sencha.com/#fiddle/m3g

    【讨论】:

    • 有趣...如果您将其更改为使用 5.1 版,您会看到我的错误。 (见this fork
    • 存储已经加载,因为它是内联数据...如果 Ext 看到 data 它不需要 autoLoad
    • 我实际上想知道它是否与this thread 相关,以及它是否是一个错误。
    • 我正在尝试检查夜间版本。
    • @incutonez - 建议您将问题更新到 5.1 :)
    猜你喜欢
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    相关资源
    最近更新 更多