开发者

Get the clicked JSON element's value with ExtJS

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:"la开发者_开发技巧debereich",
       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?


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' } 


it works with

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜