PDA

View Full Version : List store help



reminder
7 Jul 2010, 3:51 AM
hello

i tried in every possible way this combination but it still wont work...
the data is loaded, i can see it into the console but not on the list...



//returned json

{"items":[{"threadid":1000187,"group_name":"<img src='imgs/cgroup.gif' width='16' height='16' border='0'> ALFA NET"}, {"threadid":1000149,"group_name":"<img src='imgs/cgroup.gif' width='16' height='16' border='0'> ARMUS D.O.O."}]}

................................................................

Ext.regModel('group_list', {
idProperty: "threadid", fields: ["group_name"]
});

.........................................

tpl: '<tpl for="."><div class="groups"><strong>{group_name}</strong></div></tpl>',
store: new Ext.data.Store({
autoLoad: true,
storeId: "vehicle_groups_store",
model: "group_list",
proxy: new Ext.data.HttpProxy({
url: "get_groups.php",
reader: {
root: "items"
}
})
}),

any help appreciated...

thanx in advance..

Sesshomurai
7 Jul 2010, 9:20 AM
hello

i tried in every possible way this combination but it still wont work...
the data is loaded, i can see it into the console but not on the list...



//returned json

{"items":[{"threadid":1000187,"group_name":"<img src='imgs/cgroup.gif' width='16' height='16' border='0'> ALFA NET"}, {"threadid":1000149,"group_name":"<img src='imgs/cgroup.gif' width='16' height='16' border='0'> ARMUS D.O.O."}]}

................................................................

Ext.regModel('group_list', {
idProperty: "threadid", fields: ["group_name"]
});

.........................................

tpl: '<tpl for="."><div class="groups"><strong>{group_name}</strong></div></tpl>',
store: new Ext.data.Store({
autoLoad: true,
storeId: "vehicle_groups_store",
model: "group_list",
proxy: new Ext.data.HttpProxy({
url: "get_groups.php",
reader: {
root: "items"
}
})
}),

any help appreciated...

thanx in advance..

Don't you have to specify the reader type 'json'?

reminder
7 Jul 2010, 9:51 AM
yes!!! thank you very much! so tired today
regards

epalm
7 Jul 2010, 10:25 AM
I might be having a similar (or nearby) problem. I'm really struggling with the lack of consistent documentation.

Data returned (by solr):

{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"raw":"true",
"fl":"doc-id,common-id,Title,Contributors",
"indent":"on",
"start":"0",
"q":"Title:Java",
"wt":"json",
"rows":"4"}},
"response":{"numFound":59,"start":0,"docs":[
{
"doc-id":"58900",
"common-id":"/ebooks/oca1/26/javahead00herguoft",
"Title":"Java Head",
"Contributors":"Hergesheimer, Joseph"},
{
"Contributors":"Rischpater, Ray",
"Title":"Beginning Java ME platform",
"common-id":"/ebooks/ebooks0/springer/2010-02-11/2/9781430210627",
"doc-id":"260661"},
{
"Contributors":"Zukowski, John",
"Title":"Java 6 platform revealed",
"common-id":"/ebooks/ebooks0/springer/2009-12-01/4/9781430201878",
"doc-id":"265847"},
{
"Contributors":"Wood, Jo",
"Title":"Java programming for spatial sciences",
"common-id":"/ebooks/ebooks0/tf/2010-04-28/1/0203166175",
"doc-id":"252882"}
}}

As you can see, the root is thedata.response.docs, total results is thedata.response.numFound and identifying field is doc-id.

My code:

Ext.regModel('Document', {
fields: ['doc-id', 'common-id', 'Title', 'Contributors']
});

var store = new Ext.data.Store({
autoLoad: true,
model: 'Document',
proxy: new Ext.data.HttpProxy({
method: 'get',
url: 'http://books2.scholarsportal.info/SolrRequest',
reader: new Ext.data.JsonReader({
idProperty: 'doc-id',
root: 'response.docs'
}),
baseParams: {
wt: 'json',
raw: 'true',
fl: 'doc-id,common-id,Title,Contributors',
start: '0',
rows: '10',
q: 'Title:Java'
}
})
});

And I get the error this.model is undefined.

I'm autoLoading for now, but I assume once this is working I'll be able to to remove the q from baseParams and do store.load({ params: { q: 'Title:Java' } }); ?

Thanks!

Edit: Forgot two things.

Comment: the Ext.List loads and works great with local data, ie using data: [ ... ] in the store.

Question: after store.load(...) will the Ext.List be populated with the store's new data, or do I need to refresh it somehow?

TommyMaintz
7 Jul 2010, 11:08 AM
It should be populated with the stores new data automatically.

epalm
7 Jul 2010, 11:13 AM
Ok cool.

Any wisdom about the error?

Sesshomurai
7 Jul 2010, 12:29 PM
Here is my json store list hacked from the kiva example.




SearchList = Ext.extend(Ext.List, {
title: 'Search',

itemSelector: 'div.document',
singleSelect: true,
emptyText: 'No results matching that query.',

isLoaded: false,

initComponent : function() {

Ext.regModel('Search', {
fields: ['title']
});
this.store = new Ext.data.Store({model: 'Search'});

this.tpl = new Ext.XTemplate.from('search', {compiled: true});

this.on('selectionchange', function(e, row, rowdata){
this.dataPopup = new LoanInfo({
data: rowdata[0],
listeners: {
hide: function(){
this.clearSelections(true);
},
scope: this
}
});
this.dataPopup.show();
});

SearchList.superclass.initComponent.call(this);
},

filterResults : function(filterBar, values) {
var data = Ext.applyIf(values || {}, {
gender: null,
region: null,
sector: null,
sort_by: null,
q: null
});

if (data.q) {
// reset filters
}

setTimeout(function(){
if (!this.isLoaded) {
//Ext.getBody().mask(false, '<div class="loading">Loading&hellip;</div>');
}
}, 1);

this.isLoaded = false;
Ext.Ajax.request({
url: 'http://localhost:8080/symphony/touch/src/data.json',
scope:this,
failure: function() {
alert("failure");
},
success: function(response, opts) {
//Ext.getBody().unmask();
this.isLoaded = true;
var docs = Ext.decode(response.responseText);
this.update('');

var row, i, ln;
if (docs) {

for (i = 0, ln = docs.documents.length; i < ln; i++) {
row = docs.documents[i];

}


this.store.loadData(docs.documents);
this.scroller.scrollTo({x: 0, y: 0}, true);
}
}
});
}
});


and the template in the HTML



<textarea class="x-hidden-display" id="search">
<tpl for=".">
<div class="document">
<h1>{title}</h1>
<div style="font-size: 10px">{author}</div>
</div>
</tpl>
</textarea>


hth

reminder
7 Jul 2010, 1:55 PM
try

reader: {
type: 'json',
idProperty: 'doc-id',
root: 'response.docs'
},
regards

epalm
7 Jul 2010, 2:11 PM
The reader is already an Ext.data.JsonReader. Tried it though, getting the same error ("this.model is undefined").