1. #1
    Sencha User
    Join Date
    Jun 2010
    Posts
    15
    Vote Rating
    0
    amrishodiq is on a distinguished road

      0  

    Default Unanswered: How to get selected index or object of a List?

    Unanswered: How to get selected index or object of a List?


    Hi everyone,
    I try to learn Sencha, and I have difficulties in learning it, because I'm stupid I guess.
    I'm implementing a simple RSS reader. I create a PHP code to parse RSS feeds so I can use this PHP script (which has the same domain as my app) with ajax proxy.

    I'm able to show the list of news. I want to make a behaviour when user press one of the news, browser will open the URL of the selected news. The problem is I cannot get the index or object of selected item.

    Ho to do this in Sencha? It's pretty confusing because I guess I will have a method called getSelectedIndex() but I don't. Please help.

    Thanks in advance.

  2. #2
    Sencha User
    Join Date
    Jul 2011
    Location
    Utrecht
    Posts
    84
    Answers
    4
    Vote Rating
    3
    DJFliX is on a distinguished road

      0  

    Default


    In the list init I do this:
    Code:
        init: function ()
        {
            this.control(
            {
                assignmentslist: {
                    itemtap: this.onViewItemTap
                }
            })
        },
    further on in the code I use this:
    Code:
        onViewItemTap: function (c, b)
        {
            var a = c.getStore().getAt(b);
            this.application.fireEvent("navigate", {
                view: "AssignmentDetail",
                record: a
            })
        }
    The code above is mostly inspired by the SenchaCon demo at http://senchacon.senchafy.com

    T
    o clarify: b is the index of the tapped item, c is the list, a is the tapped record. I hope this helped you.

  3. #3
    Ext GWT Premium Member
    Join Date
    Apr 2009
    Location
    NYC
    Posts
    111
    Answers
    2
    Vote Rating
    1
    stan229 is on a distinguished road

      0  

    Default


    Don't ever call yourself stupid. If you were able to make it this far you definitely are not. The API docs aren't quite up to date for ST2.

    To handle the itemtap event:

    In your controller's init method (assuming you're using one)
    Code:
    this.control({
      'listxtype or selector': {
        itemtap: this.listItemTapHandler
    }
    );
    Then inside your controller you declare a function:
    Code:
    listItemTapHandler:function(list, index, item, evt) {
         // to get the item from store
         // getListStore refers to a reference inside your controller for the store. 
         this.getListStore().getAt(index);
         // or you can reference the store from the list object
         list.getStore().getAt(index);
    }
    If you're not using a controller, in your list config you have to add a listener
    Code:
    listeners: {
       itemtap: function(list,index,item, evt) { .. }
    }
    Hope this helps

  4. #4
    Sencha User
    Join Date
    Jun 2010
    Posts
    15
    Vote Rating
    0
    amrishodiq is on a distinguished road

      0  

    Default


    Thanks Stan229,

    I added these lines to my List

    Code:
    listeners: {						itemtap: function(list, index, item, evt) {
    							alert('Index: '+index);
    						}
    					}
    And now it works like a charm.

    I've described that I try to create an RSS reader app. So the data is fetched by AJAX. Using this knowledge of how to get the list index, I still confused about how to make the browser open the URL of selected item on the list?

    Here is my Store:

    Code:
    var newsStore = Ext.create('Ext.data.Store', {			model: 'News',
    			proxy: {
    				type: 'ajax',
    				url: 'feeds.php',
    				reader: {
    					type: 'json',
    					root: 'news'
    				}
    			},
    			autoLoad: true
    		});
    And here is my Model:

    Code:
    Ext.define('News', {	extend: 'Ext.data.Model',
    	fields: [
            { name: 'title', type: 'string' },
            { name: 'image', type: 'string' },
            { name: 'summary', type: 'string' },
            { name: 'link', type: 'string' }
        ]
    });
    What I need to do is something like this:
    navigate(newsStore[index].link);

    Is there any way to do this?

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar