tags:

views:

926

answers:

2

I have a JSON store:

var jsonstore = new Ext.data.ArrayStore({
    fields: ['bla', 'blubb'],
    data: [ ['bla', 'blubb'],
            ['blabla', 'blublu'],
            ['blass', 'hallo'],
            ['bam', 'guckt'] ]
});

and an extjs listview:

....
,{
       xtype: 'listview',
       name: 'abrufliste',
       store: jsonstore,
       id:"ladebereich",
       multiSelect: false,
       emptyText: 'nix da',
       reserveScrollOffset: true,
       columns: [ { header: 'Name',
                    width: .5,
                    dataIndex: 'NAME' } 
....

and a click event:

Ext.ComponentMgr.get('ladebereich').on("click",function (sthis,index,node,e ){ 
    alert("node:  "+node.childNodes[0].childNodes[0].innerHTML);});

I want to get the clicked node's value.

I do get the value with

node.childNodes[0].childNodes[0].innerHTML

, however thats a crappy solution.

I want to get the clicked Element from my jsonstore, any suggestions?

A: 

it works with

Ext.ComponentMgr.get('ladebereich').on("click",function (sthis,index,node,e ){

    var rec = jsonstore.getAt(index);
    alert(rec.get("NAME"));
});
A: 

Another way is to add a listener to your listview to respond to any click events on the listview:

,{
   xtype: 'listview',
   name: 'abrufliste',
   store: jsonstore,
   id:"ladebereich",
   multiSelect: false,
   emptyText: 'nix da',
   reserveScrollOffset: true,

   listeners:
   {
       click: function(object, selectedIndex, node, event) {
           // Get the name corresponding to the selected row.
           var rowName = object.store.getAt(selectedIndex).get("Name");
       }
   },

   columns: [ { header: 'Name',
                width: .5,
                dataIndex: 'NAME' } 
Chau