使用Ext.data.Store预先填充一个简单的Ext.FormPanel

时间:2010-08-05 22:33:23

标签: javascript extjs

嗨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存储对象获取数据。

提前致谢。

1 个答案:

答案 0 :(得分:0)

我正在尝试做同样的事情。我注意到:表单上没有“store”配置,所以你不能只是把它传给商店。

您需要手动加载记录: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel-method-loadRecord