微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – ExtJS:存储已加载,记录在表单中但不在字段中

我一开始就在努力应用我的应用程序.

this.getscoresstore().on('load', function(score, records) {
    var view = Ext.getCmp('scoreView');
    view.down('form').loadRecord(records[0].data);
    console.log(view.down('form').getRecord());
    console.log(view.down('form').getValues());
});

加载商店后,我将记录添加到表单.控制台说它已添加,但是这些字段仍然是空的.

Object { playerOne="301", playerTwo="301" }
Object { playerOne="", playerTwo="" }

任何人有想法可能是错的?

控制器:

Ext.define('Darts.controller.scores', {
    extend: 'Ext.app.Controller',

    views: [
        'score.View',
        'score.Hit'
    ],

    stores: [
        'scores'
    ],

    models: [
        'score'
    ],

    init: function() {
        this.getscoresstore().on('load', function(score, records) {
            var view = Ext.getCmp('scoreView');
            view.down('form').loadRecord(records[0].data);
            console.log(view.down('form').getRecord());
            console.log(view.down('form').getValues());
        });

        this.control({
            'scoreView' : {
                afterrender: this.formRendered
            }
        });
    },

    formRendered: function(obj) {
        console.log(obj.down('form').getRecord());
        console.log('form rendered');
    }
});

浏览次数

Ext.define('Darts.view.score.Hit' ,{
    extend: 'Ext.panel.Panel',
    alias : 'widget.scoreHit',

    title : 'Hits',
    score : 'scores',

    initComponent: function() {
        this.items = [
            {
                xtype: 'form',
                items: [
                    {
                        xtype: 'textfield',
                        name : 'playerTwo',
                        fieldLabel: 'Player 1'
                    }
                ]
            }
        ];

        this.callParent(arguments);
    }
});

Ext.define('Darts.view.score.View' ,{
    extend: 'Ext.panel.Panel',
    alias : 'widget.scoreView',
    id    : 'scoreView',

    title : 'Player scores',
    score : 'scores',

    initComponent: function() {
        this.items = [
            {
                xtype: 'form',
                items: [
                    {
                        xtype: 'numberfield',
                        name : 'playerOne',
                        fieldLabel: 'Player 1'
                    }, {
                        xtype: 'textfield',
                        name : 'playerTwo',
                        fieldLabel: 'Player 2'
                    }
                ]
            }
        ];

        this.buttons = [
            {
                text: 'Start Game',
                action: 'start'
            }
        ];

        this.callParent(arguments);
    }
});

商店

Ext.define('Darts.store.scores', {
    extend: 'Ext.data.Store',
    model : 'Darts.model.score',
    autoLoad: true,

    proxy: {
        type: 'ajax',
        api: {
            read: 'data/scores.json',
            update: 'data/updatescores.json'
        },
        reader: {
            type: 'json',
            root: 'scores',
            successproperty: 'success'
        }
    }
});

模型:

Ext.define('Darts.model.score', {
    extend: 'Ext.data.Model',
    fields: ['playerOne', 'playerTwo']
});

数据:

{
    success: true,
    scores: [
        {id: 1, playerOne: '301', playerTwo: '301'}
    ]
}

我已经尝试了数字字段,文本字段以及用’to without’和混合改变数据fom ….似乎没有什么可以帮助我.

在加载存储之前呈现字段(测试输出仍在代码中)

我真的没有想法,我看过很多主题,但没有一个适合我的问题或修复我的问题.表单字段始终保持空白.

解决方法:

我认为您的问题是您需要将Model记录传递给loadRecord方法而不是基础数据.所以尝试将第3行更改为

view.down(‘form’).loadRecord(records[0]);

作为旁注,加载整个商店只是为了获得单个记录有点奇怪.
您可能想要探索Model.load(id,{callback config})加载所需的精确记录的方法.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐