javascript – ExtJS:存储已加载,记录在表单中但不在字段中
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – ExtJS:存储已加载,记录在表单中但不在字段中,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2654字,纯文字阅读大概需要4分钟。
内容图文
我一开始就在努力应用我的应用程序.
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})加载所需的精确记录的方法.
内容总结
以上是互联网集市为您收集整理的javascript – ExtJS:存储已加载,记录在表单中但不在字段中全部内容,希望文章能够帮你解决javascript – ExtJS:存储已加载,记录在表单中但不在字段中所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。