PDA

View Full Version : how to display jason data in textfield



greg_prop
4 Oct 2012, 10:45 PM
hi!
i am using following code to fetch data using JsonStore but unable to display it in textfield, although it is being displayed in drop down.

var prices = new Ext.data.JsonStore({
autoDestroy: true,
url: 'transport.php?controller=templates&action=getPrice&propid=' + recId,
root: 'prices',
id: 'propprice',
fields: ['propertyID','price']
});

and following for textfield in toolbar.

{
xtype: 'textfield',
name: 'textfield1',
id:'textfield1',
fieldLabel: 'Text field',
value: prices

}
it displays "[object Object]"in textfield, i have tried prices[0] and prices['price'] as well in this case nothing is displayed.
Can anyone please help me on this?

sword-it
5 Oct 2012, 3:08 AM
Hi Greg,



var prices = new Ext.data.JsonStore({
})


JsonStore return Store object, if root prices contain an array of item then you can fill text field by -


value = prices.data.items[0]

greg_prop
8 Oct 2012, 5:29 AM
Thanks for help but issue is still there.I have tried this as well but nothing is displayed. When i use to write "value=prices.price[0]" the window in which this calculation is being performed, even window does not appear.

sword-it
9 Oct 2012, 10:40 PM
See this sample example-


var myStore = new Ext.data.JsonStore({
fields:['name', 'phone'],
data:{'detail':[
{ 'name': 'Lisa', "phone":"555-111-1224" },
{ 'name': 'John', "phone":"500-111-1224" }
]},
proxy: {
type: 'memory',
reader:{
root:'detail'
}
}
});

Ext.create('Ext.FormPanel', {
width: 500,
renderTo:Ext.getBody(),
title: 'Panel',
items: [{
xtype: 'textfield',
fieldLabel: 'Name',
value:myStore.data.items[0].data.name
}]
});


for your form field try this -


value : prices.data.items[0].data.price

greg_prop
20 Oct 2012, 2:48 AM
This can done if we have static data but i am fetching data from database.