PDA

View Full Version : Nested Json, Grid Panel and Store.



jeeshenlee
29 Mar 2012, 1:28 AM
How do I create a panel that reads only the "ReservationDetails" if the return Json looks like this.


{
"data":{
"Id":0,
"HotelId":6,
"Fees":0,
"FullName":null,
"SocialNumber":null,
"Email":null,
"Phone":null,
"Remark":null,
"ReservationDetails":[
{
"Id":0,
"ReservationId":0,
"RoomTypeId":8,
"DateValue":"\/Date(1333209600000)\/",
"DayValue":"asdf",
"IsAvailable":false,
"RoomRates":1,
"Quantity":1,
"Prices":1
},
{
"Id":0,
"ReservationId":0,
"RoomTypeId":19,
"DateValue":"\/Date(1333209600000)\/",
"DayValue":"asdf",
"IsAvailable":false,
"RoomRates":1,
"Quantity":1,
"Prices":1
}
]
},
"success":true
}

mitchellsimoens
29 Mar 2012, 7:21 AM
How are you getting the data? Store? Ajax request?

jeeshenlee
30 Mar 2012, 1:12 AM
Hi mitchellsimoens, I'm using Store with Ajax proxy. Below is my store definition


Ext.define('HEB.store.Reservation', {
extend: 'Ext.data.Store',
requires: 'HEB.model.Reservation',
model: 'HEB.model.Reservation',

autoLoad: false,
autoSync: false,
proxy: {
type: 'ajax',
api: {
create: '/Reservation/Create',
read: '/Reservation/GetReservationAvailabilityForHotel',
update: '/Reservation/Edit',
destroy: '/Reservation/Delete'
},
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json'
},
extraParams: {
'hotelId': '',
'startDate': '',
'endDate': '',
'unit': ''
},
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
}
});

evant
30 Mar 2012, 1:52 AM
Set the root like so:



root: 'data.ReservationDetails'