我遵循SGGraph示例中的CustomGrid_ContentManager。下面是从提要获取内容的函数。
sub GetContent()
feed = ReadAsciiFile("pkg:/images/Response.json")
if feed.Len() > 0
json = ParseJson(feed)
if json <> invalid and json.rows <> invalid and json.rows.Count() > 0
rootChildren = {
children: []
}
for each row in json.rows
if row.items <> invalid
rowAA = {
children: []
}
for each item in row.items
rowAA.children.Push(item)
end for
rowAA.Append({ title: row.title })
rootChildren.children.Push(rowAA)
end if
end for
m.top.content.Update(rootChildren)
end if
end if
end sub
我使用MainScene访问响应,如下所示:
m.grid.content.GetChild(0).GetChild(0)
在这里,我试图在GetContent((中再添加一个子项,并在主场景中使用访问,如下所示。
m.grid.content.GetChild(0).GetChild(0).GetChild(0)
但运气不好。每次都发现无效数据。我正在尝试使用以下代码。有人建议怎么做吗?
sub GetContent()
feed = ReadAsciiFile("pkg:/images/Response.json")
if feed.Len() > 0
json = ParseJson(feed)
if json <> invalid and json.rows <> invalid and json.rows.Count() > 0
rootChildren = {
children: []
}
' 'First Way Here I added extra Node
' rowNode = {
' children: []
' }
' 'Second Way Here I added extra Node
' rootChildren = {
' children: {
' rowNode : []
' }
' }
for each row in json.rows
if row.items <> invalid
rowAA = {
children: []
}
for each item in row.items
'First way using a for loop
' for each nik in item.items
' rowNode.children.Push(nik)
' end for
' rowAA.children.Push(rowNode) ' But Here not maintain item value for first node
' 'Second way I tried with directly addd
' rootChildren.children.rowNode.Push(item.items) 'But here It's give and error
rowAA.children.Push(item)
end for
rowAA.Append({ title: row.title }) 'Here Second Way It's give a error not update data here
rootChildren.children.Push(rowAA)
end if
end for
m.top.content.Update(rootChildren)
end if
end if
end sub
实际上,SGDEX内容管理器只有在使用ComponentController显示后才连接到视图。只有在那之后,您的ContentManager任务才会开始执行ContentHandler的GetContent((函数。尝试在显示视图后获取内容。