Hey
I have a json file with data that I plan to have on a server or dropbox but for now I just have it locally on the computer when testing on simulator.
When I open the file, I can’t get it to add the entries to the tableview row, they return empty everytime. The json is valid, what am I doing wrong?
json file:
{
"data": [
{
"weekDays": [
{
"day":{
"name":"Monday",
"data": [
{
"name": "Dancing",
"price": "$13.95",
"description": "Latin dance for all ages."
},
{
"name": "Bodypump",
"price": "Free",
"description": "Get toned for the summer!"
}
]
}
},
{
"day":{
"name":"Tuesday",
"data": [
{
"name": "Dancing",
"price": "$13.95",
"description": "Latin dance for all ages."
},
{
"name": "Bodypump",
"price": "Free",
"description": "Get toned for the summer!"
}
]
}
},
{
"day":{
"name":"Wednesday",
"data": [
{
"name": "Dancing",
"price": "$13.95",
"description": "Latin dance for all ages."
},
{
"name": "Bodypump",
"price": "Free",
"description": "Get toned for the summer!"
}
]
}
}
]
}
]
}
When I try to get the value for something like the name of the day I do:
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local widget = require("widget")
local json = require("json")
function scene:createScene( event )
local group = self.view
local myFile
local data
-- Above here I got the jsonFile (fileName, fileDir) function.
myFile = json.decode( jsonFile( "activities.json", system.DocumentsDirectory ) )
for i = 1, #myFile.data do
local function onRowRender( event )
local row = event.target
local rowGroup = event.view
if row.isCategory then
row.dayText = display.newRetinaText(rowGroup, myFile.data[i].weekDays.day.name, 0, 0, "Helvetica-Bold", 16)
row.dayText(display.TopLeftReferencePoint)
row.dayText.x = 10;
row.dayText.y = 5;
row.dayText:setTextColor(123, 123, 123, 255)
else
row.dayActivity = display.newRetinaText(rowGroup, myFile.data[i].weekDays.day.data.name, 0, 0, "Helvetica-Bold", 12)
row.dayActivity(display.TopLeftReferencePoint)
row.dayActivity.x = 10;
row.dayActivity.y = 10;
row.dayActivity:setTextColor(123, 123, 123, 255)
end
end
local isCategory
local rowColor
local rowHeight
local lineColor
if i == 1 or i == 6 or i == 11 then
isCategory = true
rowHeight = 24
lineColor = {0,0,0,255}
else
isCategory = false
rowHeight = 64
lineColor = {0,0,0,255}
end
myTableView:insertRow{
height = rowHeight,
rowColor = rowColor,
lineColor = lineColor,
isCategory = isCategory,
--onEvent=onRowTouch,
onRender = onRowRender
--listener = listener
}
end
end
Nothing shows up on the simulator, why is that?
Is it also possible to make so the Categories cell number is based on how many entries in the non category?
Thanks Cindy [import]uid: 65840 topic_id: 21631 reply_id: 321631[/import]