Javascript-форум (https://javascript.ru/forum/)
-   ExtJS (https://javascript.ru/forum/extjs/)
-   -   как получить данные из reader.xmlData (https://javascript.ru/forum/extjs/12642-kak-poluchit-dannye-iz-reader-xmldata.html)

lfs2008 27.10.2010 14:11

как получить данные из reader.xmlData
 
есть clients.xml

<clients>

<client>
<id>1</id>
<name>test1</name>
</client>

<client>
<id>2</id>
<name>test2</name>
</client>

<client>
<id>3</id>
<name>test3</name>
</client>
</clients>

есть reader

// create the Data Store
    var clients_store = new Ext.data.Store({
        // load remote data using HTTP

        proxy: new Ext.data.HttpProxy({
            method: 'GET',
            disableCaching:true,
            url: "clients.xml"
        }),

        reader: new Ext.data.XmlReader({
            record: 'client',
            fields: [
                {name: 'id' },
                {name: 'name'}
            ]
        })

    });

var xmlData = clients_store.reader.xmlData;



как получить по id 2 имя test2 ?

lfs2008 28.10.2010 11:02

вобщем как то так оказалось.

всем спасибо ;)

function getClientName(clientId) {
        var name = 'undefined';

        if (clients_store.getCount() > 0) {
            if (typeof(clients_store.data.items) != 'undefined') {
                for (var k in clients_store.data.items) {

                    if (typeof(clients_store.data.items[k].data) != 'undefined') {

                        if (clients_store.data.items[k].data.id == clientId) {
                            name = clients_store.data.items[k].data.name;
                        }
                        // alert(clients_store.data.items[k].data.name);
                    }
                    ;
                }
            }
        }
        return name;
    }

VKS 28.10.2010 11:47

var recIndex = store.find('id', clientId);
var rec = store.getAt(recIndex);

Get the Record with the specified id

lfs2008 02.11.2010 19:12

супер, спс!


Часовой пояс GMT +3, время: 11:57.