开发者

Can't get Data Store working in Sencha Touch with scripttag Proxy and JSONP

开发者 https://www.devze.com 2023-03-12 11:23 出处:网络
I\'ve got a panel that is supposed to be consuming JSONP from an external web service. models/VimeoModel.js

I've got a panel that is supposed to be consuming JSONP from an external web service.

models/VimeoModel.js

rpc.models.VimeoMode开发者_高级运维l = Ext.regModel('rpc.models.VimeoModel', {
    fields: [
        {name: 'id', type: 'int'},
        {name: 'title', type: 'string'}
    ]
});

views/VideoView.js

rpc.views.VideoView = new Ext.Panel({
    id: 'VideoView',
    title: "Videos",
    tpl: VimeoTemplate,
    iconCls: "tv",
    dockedItems: [{ xtype: "toolbar", title: "Videos"}],
    store: 'rpc.stores.VimeoStore'
});

stores/VimeoStore.js

rpc.stores.VimeoStore = new Ext.data.Store({
    id: 'VimeoStore',
    model: 'rpc.models.VimeoModel',
    proxy: {
        type: 'scripttag',
        url: WebService.Url + WebService.Vimeo.Read,
        reader: {
            type: 'jsonp',
            root: 'results'
        }
    },
    autoLoad: true
});

templates/VimeoTemplate.js

var VimeoTemplate = new Ext.XTemplate([
    '<tpl for=".">',
        '<div>',
            '{title}',
        '</div>',
    '</tpl>'
]);

Unfortunately when the page loads, there is no data being populated into the VideoView.

The WebService request looks like this

http://rpc.infinitas.ws/Vimeo/Read?_dc=1308067234445&limit=25&callback=stcCallback1001

It's returning a JSONP response

stcCallback1001({"results":[{"id":25036464,"title":"Power of A Surrendered Li..."},{"id":25036610,"title":"Child Dedication June 2011"},{"id":24734142,"title":"Power of A Surrendered Li..."},{"id":24884833,"title":"Finance Update June 2011"},{"id":24587711,"title":"Papua, Indonesia Sharing ..."},{"id":24232427,"title":"ICHTHUS: Coming King"},{"id":23868560,"title":"ICHTHUS: Healer"},{"id":23486615,"title":"ICHTHUS: Sanctifier"},{"id":23211649,"title":"ICHTHUS: Saviour"},{"id":23867961,"title":"Elder Announcement re: Br..."},{"id":22998163,"title":"Triumph of Grace: Risen L..."},{"id":23687914,"title":"Triumph of Grace: Reignin..."},{"id":23692076,"title":"KINGDOM now: For Thine Is..."},{"id":23694183,"title":"KINGDOM now: Deliver Us F..."}],"success":true});stcCallback1001({"results":[{"id":25036464,"title":"Power of A Surrendered Li..."},{"id":25036610,"title":"Child Dedication June 2011"},{"id":24734142,"title":"Power of A Surrendered Li..."},{"id":24884833,"title":"Finance Update June 2011"},{"id":24587711,"title":"Papua, Indonesia Sharing ..."},{"id":24232427,"title":"ICHTHUS: Coming King"},{"id":23868560,"title":"ICHTHUS: Healer"},{"id":23486615,"title":"ICHTHUS: Sanctifier"},{"id":23211649,"title":"ICHTHUS: Saviour"},{"id":23867961,"title":"Elder Announcement re: Br..."},{"id":22998163,"title":"Triumph of Grace: Risen L..."},{"id":23687914,"title":"Triumph of Grace: Reignin..."},{"id":23692076,"title":"KINGDOM now: For Thine Is..."},{"id":23694183,"title":"KINGDOM now: Deliver Us F..."}],"success":true});

When I fire up the Chrome Javascript Console I get an error

Read:1 Uncaught ReferenceError:stcCallback1001 is not defined

And here's the staging app if you need more info

http://rpcm.infinitas.ws


The problem is in the javascript you're returning. You're outputting the callback twice. If you click on the jsonp link in your question you should see two stcCallback1001 invocations. Since the callback is removed after the first one the second one fails.

BTW You don't need to specify the callbackParam.


See the answer I provided on your other question, Sencha Touch JSONP Store Data not showing up in Panel.

The main issue is that you want to change the proxy from type: 'scripttag' to type: 'jsonp'. Once you do that, the JSONP proxy should take care of creating the appropriate callback functions before it makes the request to the server.


Making the reader type from 'jsonp to 'json' should bring back the correct result.

0

精彩评论

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