PDA

View Full Version : Can itemSelector and root in a DataView take a variable?



craigwalshuk
31 Aug 2011, 3:48 AM
I'm using javascript to get todays date. I have a json file that has the following format:



{
"january": [
{"book": "The Hobbit"},
{"quote": "Quote for day one"},
{"quote": "Quote for day two"},
{"quote": "Quote for day three"},
{"quote": "Quote for day four"},
{"quote": "Quote for day five"}
...
],
"february": [
{"book": "Harry Potter"},
{"quote": "Quote for day one"},
{"quote": "Quote for day two"},
{"quote": "Quote for day three"},
{"quote": "Quote for day four"},
{"quote": "Quote for day five"}
...
],
...
}


On my website I can parse the json and access it as an array (month[day]) to pull out the correct quote for that day. Now I am using a DataView in sencha touch and I would like to do the same thing but it seems like the root section in the reader and the item itemSelector don't accept variables. Here is what I want to acheive:



var today = new Date();
var month = today.getMonth();
var day = today.getDate();

Ext.regModel('Book', {
fields: [
{name: 'month', type: 'string'},
{name: 'quote', type: 'string'}
]
});

var bookList = new Ext.DataView({
store: new Ext.data.Store({
model: 'Book
proxy: {
type: 'ajax',
url : 'app/quoteData.json',
reader: {
type: 'json',
root: month <--- Here I want to specify the month
}
},
autoLoad : true
}),
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div class="item">',
'<h4>{month}</h4>',
'<p>{quote}</p>',
'</div>',
'</tpl>'
),
itemSelector: day, <-- Here I want to specify the day
fullscreen: true
});


Is this possible?

arkos
31 Aug 2011, 6:42 AM
getMonth and getDay return an integer. 0 for january, 1 for febuary... ... ...

try something like this:




var myMonth = new Date();
var currentMonth = myMonth.getMonth();
var monthArray = new Array("january", "febuary", "march" ... ... "december");
var currentRoot = monthArray[currentMonth];