View Full Version : How to correctly use Ext.ScriptTagProxy

1 Apr 2011, 9:12 AM
Hello all!
I have a question about the usage of Ext.ScriptTagProxy. For completeness I have included all of my js file(It's not very big). Now in the
initComponent function is where I try to create a new store using Ext.ScriptTagProxy. In FireBug I can clearly see that the json object is being fetched as jsonp, which I believe is correct, but the grid panel's store has a count of zero. I have searched the forums and the api doc so please forgive me if this is an error on my part. Please give me your insight, and thank you for your time.


App.NewsGridPanel = Ext.extend(Ext.grid.GridPanel, {
title : 'News',
id :'newsGridPanel',
layout :'fit',
border :false,
autoHeight :true,
autoWidth :true,
store : this.store,
//selModel : new Ext.grid.CheckboxSelectionModel(this.selModelConfig),
columns : this.columns,
viewConfig :{forceFit: true, deferEmptyText: false, scrollOffset:2},

initComponent:function() {
// Called during component initialization
var newsGridPanel = Ext.getCmp('newsGridPanel');
newsGridPanel.addListener("rowclick", this.rowClicked, newsGridPanel);
this.columns = [
{id : 'contentColumn',
header : "News",
dataIndex : "abstract",
renderer : function(val, x, record, rowIndex, columnIndex, store) {
var contentId = Ext.id();
//Ext.getCmp('newsGridPanel').addRemoveBtn.defer(10, this, [val, contentId, record, rowIndex, columnIndex, store]);
return '<h2>This is ' + record + 'row ;)</h2>'}
];//eo columns
var appid = 'appid=FTrRc2nV34EMdwMeZKZpq4u1ppjMrYCXTYidQ9AfKs8VAw9FzN6B5JX6WPzJfukBw8LE6IhcRYurk83djyfB75XUN4yB5Os-';
var start = '&start=0';
var count = '&count=1';
var format = '&format=json';
var url = 'http://boss.yahooapis.com/ysearch/news/v1/"' + 'war' + '"?' + appid + start + count + format;
this.store = new Ext.data.Store({
id : 'newsGridPanel',
root : 'resultset_news',
idProperty : 'title',
totalProperty : 'count',
reader : new Ext.data.JsonReader({root : 'resultset_news',
fields : ['abstract', 'clickurl', 'date', 'language', 'source', 'sourceurl', 'time', 'title', 'url']}),
proxy : new Ext.data.ScriptTagProxy({url : url})

});//eo store

// Before parent code

// Call parent (required)
App.NewsGridPanel.superclass.initComponent.apply(this, arguments);

// After parent code
// e.g. install event handlers on rendered component
//this.on('rowclick', this.selectBook, this);

// grid widgets

onRender: function(){
// Call parent (required)
App.NewsGridPanel.superclass.onRender.apply(this, arguments);
// After parent code


// register xtype to allow for lazy initialization
Ext.reg('newsGridPanel', App.NewsGridPanel);

1 Apr 2011, 10:16 AM
As the docs (http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Store&member=load) say, load() is asynchronous, so calling getCount immediately after load will return 0 - you need to wait for the load to complete. Add a load event handler to your store and then you can log getCount, e.g.,

this.store.on('load', function(records, options, success)

1 Apr 2011, 10:27 AM
Thank you for your reply Fay, the code snippet helped. Turns out that I was not specifying the correct root for my reader.
I had,
root : 'child'

when what I needed was root : 'parent.child'.

Once again thank you for your quick reply, and happy coding ;)