[英]Using Ext.data.Store to pre-populate a simple Ext.FormPanel
嗨ExtJS開發人員。 我是ExtJS的新手,正在嘗試使用從外部XML資源讀取的數據來預填充基本表單。 我似乎無法預先加載數據,以下是代碼:
Ext.onReady(function(){
// getting the UUID from what is passed on by REST Controller
var myuuid = location.pathname;
var myurl = myuuid.replace('/edit/director','');
// read data from url and store
var store = new Ext.data.Store({
// load using HTTP, point this to the xml you want to test
url: myurl,
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have a "stats tag
record: 'stats',
id: 'serial-number',
}, [
// set up the fields mapping into the xml doc
{name: 'director', mapping: 'director'},
'director-phone', 'director-phone-ext', 'director-email', 'website','title','published-name'
])
});
// create a form
var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
store: store,
renderTo: 'example-form',
url:'save-form.php',
frame:true,
title: 'Edit Director Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'Director',
name: 'director',
displayField: 'director',
valueField: 'director',
},{
fieldLabel: 'Telephone',
name: 'director-phone',
dataIndex: 'director-phone'
},{
fieldLabel: 'Extension',
name: 'director-phone-ext',
dataIndex: 'director-phone-ext'
}, {
fieldLabel: 'Email',
name: 'director-email',
vtype:'email'
}
],
buttons: [{
text: 'Save'
},{
text: 'Cancel'
}]
});
store.load();
simple.render();
});
我已經分別測試了Ext.data.store,以查看變量myurl是否實際上正在獲取正確的XML資源路徑。 這段代碼仍然不會“加載”讀取的XML。
我究竟做錯了什么? 我無法理解基本表單對象如何從XML存儲對象獲取數據。
在此先感謝。
我正在嘗試做同樣的事情。 我注意到:表單上沒有“ store”配置,因此您不能只是將其傳遞給商店。
您需要手動加載記錄: http : //docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel-method-loadRecord
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.