1. #1
    Sencha User
    Join Date
    Oct 2008
    Posts
    23
    Vote Rating
    0
    danic is on a distinguished road

      0  

    Question Unanswered: Trouble with ScriptTagProxy/Store

    Unanswered: Trouble with ScriptTagProxy/Store


    Hi guys.


    I am trying to implement some simple Tweeter search using the already provided TwitterProxy (demos/twitter).
    Code:
    Ext.data.TwitterProxy = Ext.extend(Ext.data.ScriptTagProxy, {
        //this is the url we always query when searching for tweets
        url: 'http://search.twitter.com/search.json',
        perPage: 50,
        filterParam: undefined,
        
        constructor: function(config) {
            config = config || {};
            
            Ext.applyIf(config, {
                extraParams: {
                    suppress_response_codes: true
                },
                
                reader: {
                    type: 'json',
                    root: 'results'
                }
            });
            
            Ext.data.TwitterProxy.superclass.constructor.call(this, config);
        },
        
        /**
         * We need to add a slight customization to buildRequest - we're just checking for a filter on the 
         * Operation and adding it to the request params/url, and setting the start/limit if paging
         */
        buildRequest: function(operation) {
            var request = Ext.data.TwitterProxy.superclass.buildRequest.apply(this, arguments),
                filter  = operation.filters[0],
                params  = request.params;
            
            Ext.apply(params, {
                page: 1,
                lang: "en",
                result_type: "mixed",
                rpp: 15
            });
            
            if (filter) {
                Ext.apply(params, {
                    q: filter.value
                });
                
                //as we're modified the request params, we need to regenerate the url now
                request.url = this.buildUrl(request);
            }
            
            return request;
        }
    });
    
    
    Ext.data.ProxyMgr.registerType('twitter', Ext.data.TwitterProxy);

    I have also defined a store:
    Code:
    app.stores.TwittsStore = new Ext.data.Store({
        model: "Tweet"         
    });

    and a model:


    Code:
    Ext.regModel("Tweet", {
        fields: [
            {name: "id", type: "int"},
            {name: "text", type: "string"},
            {name: "from_user", type: "string"},
            {name: "profile_image_url", type: "string"}
        ],
        proxy: 'twitter'     
    });

    I create the list containing tweets in the following manner:
    Code:
    app.views.SomePanel.twittsList = new Ext.List({
        id: "twittsList",
        store: app.stores.TwittsStore,
        emptyText: 'No tweets found',
        disableSelection: true,
        itemTpl: new Ext.XTemplate(
            '<img src="{profile_image_url}" />',
            '<div class="x-tweetanchor"></div>',
            '<div class="tweet-bubble">',
                '<div class="tweet-content">',
                    '<h2>{from_user}</h2>',
                    '<p>{text:this.linkify}</p><strong></strong>',
                    '<span class="posted">{created_at}</span>',
                '</div>',
            '</div>',
            {
                linkify: function(value) {
                    return value.replace(/(http:\/\/[^\s]*)/g, "<a target=\"_blank\" href=\"$1\">$1</a>");
                }
            }
        )  
    });

    I have a refresh button which does the following:
    Code:
    app.views.SomePanel.twittsList.store.load();
    app.views.SomePanel.twittsList.refresh();

    However, I always get the 'No tweets found' message in the list (the default text). I have checked and debugged the code a bit: the call to the tweeter search.json is made, the result is fetched correctly within the Ext.data.ScriptTagProxy.createRequestCallback method - the options variable.


    What seems to be the problem here? Any ideas and suggestions are welcome.


    Best regards,
    Dani

  2. #2
    Sencha User
    Join Date
    Oct 2008
    Posts
    23
    Vote Rating
    0
    danic is on a distinguished road

      0  

    Default Fixed

    Fixed


    Nevermind that, I just forgot to set the remoteFilter property to true.

    Regards,
    Dani