PDA

View Full Version : no data in panel



kjcr
16 Oct 2012, 10:14 PM
hello
i'm new to Extjs
i have a problem




1. my json
{"root":
"success":"false"
"items":[
{
"type":"Error",
"title":"Title",
"message":"Message",
"key":""
},
{
"type":"Error",
"title":"Title",
"message":"Message",
"key":""
}
]}

2.store

var project_val = Ext.create('Ext.data.ArrayStore', {
model: 'project_val',
autoLoad : true
});



3.model

Ext.define('project_val',{
extend:'Ext.data.Model',
fields:[
{name:'success',type:'string'},
{name:'type',type:'string',mapping:'items.type'},
{name:'title',type:'string',mapping:'items.title'},
{name:'message',type:'string',mapping:'items.message'},
{name:'key',type:'string',mapping:'items.key'}
],
hasOne: {model:'items',name:'items'},
proxy:{
type: 'ajax',
url:'resource/json/result.json',
reader:{
type:'json',
root:'root'
}
}
});

Ext.define('items',{
extend:'Ext.data.Model',
fields:[
{name:'type',mapping:'record[0].type'},
{name:'title',mapping:'record[1].title'},
{name:'message',mapping:'record[2].message'},
{name:'key',mapping:'record[3].key'}
],
belongTo:'project_val'
});



4. view

//xtemplate
var temp = new Ext.Template(
'<div>hello</div>'
);

// panel

var valPanel = Ext.create('Ext.panel.Panel',{
store:project_val,
title:'Your dataset show below error',
id:'gridVal',
tpl:temp
});

kjcr
16 Oct 2012, 10:15 PM
i see panel on window
but no data displayed.

help me please

vietits
16 Oct 2012, 10:30 PM
Firstly, your Json data is incorrect. So you should check it again.

kjcr
16 Oct 2012, 11:01 PM
{
"root": [{
"success": "false",
"items": [{
"type": "error",
"title":"Title",
"message":"Message",
"key":"this data error"
},{
"type":"Error",
"title":"Title",
"message":"Message",
"key":"019 error"
}]
}]
}

kjcr
16 Oct 2012, 11:03 PM
Ext.define('items',{
extend:'Ext.data.Model',
fields:[
{name:'type',type:'string'},
{name:'title',type:'string'},
{name:'message',type:'string'},
{name:'key',type:'string'}
],
belongTo:'project_val'
});

vietits
16 Oct 2012, 11:23 PM
According to your new json data and items model. You should fix project_val model as below:


Ext.define('project_val',{
extend:'Ext.data.Model',
fields:[
{name:'success',type:'string'},
// {name:'type',type:'string',mapping:'items.type'},
// {name:'title',type:'string',mapping:'items.title'},
// {name:'message',type:'string',mapping:'items.message'},
// {name:'key',type:'string',mapping:'items.key'}
],
// hasOne: {model:'items',name:'items'},
hasMany: {model:'items',name:'items'},
proxy:{
type: 'ajax',
url:'resource/json/result.json',
reader:{
type:'json',
root:'root'
}
}
});




4. view
//xtemplate
var temp = new Ext.Template(
'<div>hello</div>'
);

// panel

var valPanel = Ext.create('Ext.panel.Panel',{
store:project_val,
title:'Your dataset show below error',
id:'gridVal',
tpl:temp
});


What do you want to do with this code?

kjcr
16 Oct 2012, 11:51 PM
thankyou for your help!
and..

I want to show error message
this is just test.

if success==false
i want to show error

else have nothing to do.

kjcr
17 Oct 2012, 12:05 AM
But in store there is no data.:(:(

when i use below

Ext.define('project_val',{
extend:'Ext.data.Model',
fields:[
{name:'success',type:'string'}
{name:'type',type:'string',mapping:'items.type'},
{name:'title',type:'string',mapping:'items.title'},
{name:'message',type:'string',mapping:'items.message'},
{name:'key',type:'string',mapping:'items.key'}
],
hasMany: {model:'items',name:'items'},

});

Ext.define('items',{
extend:'Ext.data.Model',
fields:[
{name:'type',type:'string'},
{name:'title',type:'string'},
{name:'message',type:'string'},
{name:'key',type:'string'}
],
belongTo:'project_val'
});


store has data.
but value of type,title, message,key is just ''.

do you have any solution??

vietits
17 Oct 2012, 12:33 AM
Below is your code that I have up to now. Running this code and you will see project_val store will contain one record {"success": "false"}. You can access its items thru <record>.items(). This will return a store that contains all items of the record.


Ext.onReady(function(){
Ext.define('project_val',{
extend:'Ext.data.Model',
fields:[
{name:'success',type:'string'}
],
hasMany: {model:'items',name:'items'},
proxy:{
type: 'ajax',
url:'index.json',
reader:{
type:'json',
root:'root'
}
}
});


Ext.define('items',{
extend:'Ext.data.Model',
fields:[
{name:'type',type:'string'},
{name:'title',type:'string'},
{name:'message',type:'string'},
{name:'key',type:'string'}
],
belongTo:'project_val'
});


var project_val = Ext.create('Ext.data.Store', { // use Store instead of ArrayStore
model: 'project_val',
autoLoad : true
});


console.log(project_val);
});

index.json


{
"root": [{
"success": "false",
"items": [{
"type": "error",
"title":"Title",
"message":"Message",
"key":"this data error"
},{
"type":"Error",
"title":"Title",
"message":"Message",
"key":"019 error"
}]
}]
}

kjcr
17 Oct 2012, 1:15 AM
Thankyou very much.

very helpful!!

and i show some data in my panel.
but still other data in items is not showed in my panel
please look my panel please,

my panel

var valPanel = Ext.create('Ext.panel.Panel',{
data:project_val,
title:'Your dataset show below error',
id:'gridVal',
tpl:new Ext.XTemplate(
'<tpl for=".">',
'<div><b>Title:</b> {data.success}</div>',
'<div><b>Message:</b> {data.items()}<div>',
'</tpl>'),
});

data.success show its data 'false',
but data in items is not showed.

Do you have idea about this??

thanx

vietits
17 Oct 2012, 2:14 AM
Try this:


var project_val = Ext.create('Ext.data.Store', {
model: 'project_val',
autoLoad : true,
listeners: {
load: function(){
console.log(project_val, project_val.getAt(0).items());


var valPanel = Ext.create('Ext.panel.Panel',{
renderTo: Ext.getBody(),
width: 400,
height: 200,
data: project_val,
title:'Your dataset show below error',
id:'gridVal',
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div><b>Title:</b> {data.success}</div>',
'<div><b>Message:</b><ul>',
'<tpl for="items()">',
'<li>{data.type} - {data.title} - {data.message} - {data.key}</li>',
'</tpl>',
'</ul></div>',
'</tpl>'
)
});
}
}
});