【问题标题】:ExtJS Hardcoded Model ExampleExtJS 硬编码模型示例
【发布时间】:2014-02-12 21:18:40
【问题描述】:

我有以下模型,它使用代理通过 AJAX 从 URL 检索 JSON。

Ext.define('RateManagement.model.Currency', {
    extend: 'Ext.data.Model',

    fields: [
        { name: 'id', type: 'string' },
        { name: 'name', type: 'string' },
        { name: 'code', type: 'string' }
    ],

    proxy: {
        type: 'ajax',
        url: 'currencies.json'
    }

});

如何将其更改为使用静态硬编码值而不是数据库驱动值?

我一直在查看文档http://docs.sencha.com/extjs/4.0.7/#!/api/Ext.data.Model 并且遇到了Raw,但我不确定如何使用它或者它是否是正确的属性。

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    类似:

    var store = new Ext.data.Store({
        model: 'RateManagement.model.Currency',
        data: [{
            id: 1,
            name: 'Foo',
            code: 'abc'
        }]
    });
    

    【讨论】:

    • 那么,我应该省略fields 属性吗?
    • 这些字段在您的模型中定义。
    【解决方案2】:

    您可以为您的模型使用memory proxy

    Ext.define('RateManagement.model.Currency', {
        extend: 'Ext.data.Model',
    
        fields: [
            { name: 'id', type: 'string' },
            { name: 'name', type: 'string' },
            { name: 'code', type: 'string' }
        ],
    
        proxy: {
            type: 'memory',
            reader: 'json',
            data: [
                {id: 1, name: 'Foo', code: 'foo'},
                {id: 2, name: 'Bar', code: 'bar'},
                {id: 3, name: 'Baz', code: 'baz'}
            ]
        }
    });
    

    【讨论】:

    • 谢谢,我试试看。
    猜你喜欢
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    相关资源
    最近更新 更多