如何从XML加载tagfield中的数据

时间:2017-05-22 12:04:38

标签: javascript extjs extjs4

我正在尝试将数据从xmll加载到tagfield。但我不确定失败的原因。谁能告诉我这里出了什么问题。 我正在使用不同功能的tagfield商店。我不知道甚至不能在那里做调试。

Null

MyXml:

Ext.define('MyApp.view.main.List', {
    extend: 'Ext.form.Panel', 
    title: 'Simple Form',
    xtype: 'mainlist',
    bodyPadding: 5,
    width: 350,

    // The form will submit an AJAX request to this URL when submitted
    url: 'save-form.php',

    // Fields will be arranged vertically, stretched to full width
    layout: 'anchor',
    defaults: {
        anchor: '100%'
    },

    // The fields
    defaultType: 'textfield',
    items: [{
        fieldLabel: 'First Name',
        name: 'first',
        allowBlank: false
    },{
        xtype: 'tagfield',
        fieldLabel: 'Select a Show',
        store: this.TagStore,
        //displayField: 'show',
        valueField: 'id',
        queryMode: 'local',
        filterPickList: true,
    }],
    renderTo: Ext.getBody(),

    TagStore : function(){
        debugger;
        var combstore = Ext.create('Ext.data.Store', {
            autoLoad: true,
            fields: [{
                name: 'value',
                mapping: "ITEMID",
                type: 'string'
            }, {
                name: 'name',
                mapping: "TITLE",
                type: 'string'
            }],
            proxy: new Ext.data.HttpProxy({
                type: 'ajax',
                actionMethods: {
                    read: "GET"
                },
                url: "localhost/MyApp/resources/data.xml",
                headers: {
                    'Accept': 'application/json; charset=utf-8'
                },
                reader: {
                    type: 'xml',
                    rootProperty: 'R.D.Result'
                },
                extraParams: {
                    strIPXML: strIPXML
                }
            })
        });
    }
});

任何人都可以帮我解决如何通过extJS中的xml加载数据

1 个答案:

答案 0 :(得分:0)

刚才有时候在sencha小提琴上玩你的问题,这是基本的工作代码(Atleast看到tagfield商店填充)。 使用:Ext JS 5.1.1.451 - 灰色



    Ext.application({
    name : 'Fiddle',

    launch : function() {
      Ext.define('MyApp.view.main.List', {
    extend: 'Ext.form.Panel', 
    title: 'Simple Form',
    xtype: 'mainlist',
    bodyPadding: 5,
    width: 350,

    // The form will submit an AJAX request to this URL when submitted
    url: 'save-form.php',

    // Fields will be arranged vertically, stretched to full width
    layout: 'anchor',
    defaults: {
        anchor: '100%'
    },

    // The fields
    defaultType: 'textfield',
    items: [{
        fieldLabel: 'First Name',
        name: 'first',
        allowBlank: false
    },{
        xtype: 'tagfield',
        fieldLabel: 'Select a Show',
        store:Ext.getStore('TagStore'),
        displayField: 'name',
        valueField: 'value',
        queryMode: 'local',
        filterPickList: true,
    }],
    renderTo: Ext.getBody(),

    TagStore : function(){
        var combstore = Ext.create('Ext.data.Store', {
            autoLoad: true,
            storeId:'TagStore',
            fields: [{
                name: 'value',
                mapping: "@ITEMID",
                type: 'string'
            }, {
                name: 'name',
                mapping: "@TITLE",
                type: 'string'
            }],
            proxy: {
                type: 'ajax',
                url: "data1.xml",
                reader: {
                    type: 'xml',
                    record: 'E',
                    rootProperty:'EMAIL'
                }
            }
        });
        return combstore;
    }
});
var form = Ext.create('MyApp.view.main.List');
form.TagStore();
var store = Ext.getStore('TagStore');
form.child('[xtype=tagfield]').bindStore(store);
    }
});

<强> data1.xml作为

 <?xml version="1.0" encoding="UTF-8"?>
<EMAIL>
<E TITLE="test@test.com" ITEMID="A" />
<E TITLE="test2@rwer.wer" ITEMID="B" />
</EMAIL>