【问题标题】:Configuring an Ext.data.XmlStore to obtain custom tags from response配置 Ext.data.XmlStore 以从响应中获取自定义标签
【发布时间】:2011-05-09 10:13:18
【问题描述】:

您好,我从服务器返回了以下 xml: 代码:

link text

我似乎无法正确设置 xml 存储配置。特别是,我希望能够获得自定义标签:名称、内部和引用,它们是返回的结果集的属性。 非常感谢!

【问题讨论】:

    标签: extjs tags xmlstore


    【解决方案1】:

    试试这段代码(用你的 xml 源代码替换 test.xml)

        // create the Data Store
    var store = new Ext.data.Store({
        // load using HTTP
        url: 'test.xml',
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
               // records will have an "customer" tag
               record: 'customer',
           }, ['id','field1', 'field2', 'field3'])
    });
    
    // create the grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {header: "id", width: 120, dataIndex: 'id', sortable: true},
            {header: "field1", width: 180, dataIndex: 'field1', sortable: true},
            {header: "field2", width: 115, dataIndex: 'field2', sortable: true},
            {header: "field3", width: 100, dataIndex: 'field3', sortable: true}
        ],
        renderTo:'example-grid',
        width:540,
        height:200
    });
    store.load();
    

    为了获取标签:名称、内部和引荐,我使用了 Ext.DomQuery,它使您能够解析为 xml(尝试用于内部和引荐)

    Ext.Ajax.request({
           url: 'test.xml',
           success: function(response){
            console.debug(response);
            if (Ext.DomQuery.selectNode("/rootNode/name", response.responseXML)) {
                var name = Ext.DomQuery.selectValue("/rootNode/name",  response.responseXML);
                console.debug(name);
            } 
    
           },
           failure: function () { console.log('failure');}
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多