Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
EnTerr
Level 8

Re: Loop through a content node

"btpoole" wrote:
In the post I was referencing that setting m.top.content=content doe not work so setting m.top.content=data as shown above does.  As for the chat room, I didn't know this existed, thanks for pointing this out.   Thanks again.

Yes but did you at any one point tell us what is the type of "m.top.content" ?
If that code is inside a Task component, then you must have declared content like below - but what TYPE ?
<component name = "myTask" extends = "Task" >
  <interface>
   <field id="content" type = "????" />
 </interface>
...
</component>
0 Kudos
btpoole
Level 7

Re: Loop through a content node

Sorry, the type is node.
0 Kudos
EnTerr
Level 8

Re: Loop through a content node

Ok, so back to your original approach:
"btpoole" wrote:

data=m.ContentTaskp.getChildren(1e4, 0)
for each item in data
?item
end for


I believe what you were missing was m.ContentTaskp.content.getChildren():
data = m.ContentTaskp.content.getChildren(1e4, 0)
for each item in data
 ? item
end for

I.e. you were looking at the children of task and it had no children, instead should been the content field of the task. Both are nodes, so confusion may happen
0 Kudos
btpoole
Level 7

Re: Loop through a content node

"EnTerr" wrote:
Ok, so back to your original approach:
"btpoole" wrote:

data=m.ContentTaskp.getChildren(1e4, 0)
for each item in data
?item
end for


I believe what you were missing was m.ContentTaskp.content.getChildren():
data = m.ContentTaskp.content.getChildren(1e4, 0)
for each item in data
 ? item
end for

I.e. you were looking at the children of task and it had no children, instead should been the content field of the task. Both are nodes, so confusion may happen



I am truly sorry for the frustration I have caused on this topic. Let me reset and see if this helps.
The task consist of with some irrelevant code left out. This works.
<component name = "ContentReader_P" extends = "Task" >
  <interface>
  <field id = "Content" type = "node" />
 </interface>
  <script type = "text/brightscript" >
  <![CDATA[
sub init()
m.top.functionName = "readcontent"
end sub

Function readcontent() as object
Content = CreateObject("roSGNode", "ContentNode")
for each item in result
data = Content.createChild("ContentNode")
data.addFields ({result: item})
?data
end for
m.top.content=data
end Function
]]>

Back in the brs code I have the following
sub setGridcontent()
data=m.ContentTaskp.content.result
for each item in data
  ?item
end for
end sub

The ?item gives me each field name in the m.ContentTaskp.content.result (field names are channel, show, url).  I have tried the getchildren(1e,0) as you posted but return invalid. The only way I could get back anything is from what I have posted here. So,  for example, if one of the fields in the m.ContentTaskp.content.result is called channel, how would the value of the channel field be obtained? From what I see the "result" is a roAssociativeArray component part of the rosgnode.
0 Kudos
EnTerr
Level 8

Re: Loop through a content node

"btpoole" wrote:
I am truly sorry for the frustration I have caused on this topic. Let me reset and see if this helps.
The task consist of with some irrelevant code left out. This works.
...

Aha! I see your problem - it's that you are setting in Content the last Data only, the last Item. Seems you still get confused with nested structures, i seem to remember that from the past. No sweat, let me simplify that:
<component name = "ContentReader_P" extends = "Task" >
  <interface>
   <field id = "Content" type = "assocarray" />
 </interface>
  <script type = "text/brightscript"><![CDATA[
...
Function readContent() as object
 ... ' get here first `result` as roArray of items, you already have that
 m.top.content = {result: result}
end Function
]]>
</component>

... and that's it, you are golden. I just changed the field type to roAA and added the array as an entry inside. setGridContent() should see it now.
0 Kudos
btpoole
Level 7

Re: Loop through a content node

"EnTerr" wrote:
"btpoole" wrote:
I am truly sorry for the frustration I have caused on this topic. Let me reset and see if this helps.
The task consist of with some irrelevant code left out. This works.
...

Aha! I see your problem - it's that you are setting in Content the last Data only, the last Item. Seems you still get confused with nested structures, i seem to remember that from the past. No sweat, let me simplify that:
<component name = "ContentReader_P" extends = "Task" >
  <interface>
   <field id = "Content" type = "assocarray" />
 </interface>
  <script type = "text/brightscript"><![CDATA[
...
Function readContent() as object
 ... ' get here first `result` as roArray of items, you already have that
 m.top.content = {result: result}
end Function
]]>
</component>

... and that's it, you are golden. I just changed the field type to roAA and added the array as an entry inside. setGridContent() should see it now.

Once again you have guided me thru. Very sorry for the frustration I will follow your recommendations for making request in the future. I had realized the location of m.top.content and moved to inside the loop but didn't recognize changing the type to assocarray. This made a big difference. Thanks again.
0 Kudos