Forum Discussion

mkdir1995's avatar
mkdir1995
Visitor
8 years ago

How to add custom field to Node?

I can't seem to find anything on the forum or in the SDK on how to add a custom field into the node object. For example, a roSGNode is set up like this:
 
<Component: roSGNode> =
{
    change: <Component: roAssociativeArray>
    focusable: false
    focusedChild: <Component: roInvalid>
    id: ""
    DESCRIPTION: ""
    HDBACKGROUNDIMAGEURL: ""
    HDPOSTERURL: ""
    RELEASEDATE: ""
    STREAMFORMAT: ""
    TITLE: "cartoon 1"
    URL: ""
}



Now, using my server data, I know I can program my content with the corresponding Content Meta Data. I can set the TITLE, URL, DESCRIPTION, id etc because that is what is provided to me in the roSGNode. What if I need custom fields in order to continue setting up my application? For example, I need to add a TYPE right under the 'URL' in the node above.
I tried using .addFields() but that didn't seem to work.

Any help is greatly appreciated since I've been trying for a few days and can't figure it out. Thanks!

6 Replies

  • Or you can add fields dynamically, without extending-through-XML/compilation - as simple as:
    myNode.addFields({myNewField: value1, more2: 7})
  • you extend the node, then you can add any fields you want.
    For example:
    <?xml version="1.0" encoding="utf-8" ?>
    <component name="media_item" extends="ContentNode">
    <interface>
    <field id="thumbnail" type="string" />
    <field id="content_type" type="string" />
    <field id="title" type="string" />
    <field id="entitlement" type="string" />
    <field id="guid" type="string" />
    <field id="duration" type="float" />
    <field id="category" type="string" />
    <field id="ratings" type="array" />
    <field id="genres" type="array" />
    <field id="daypart" type="string" />
    <field id="program" type="string" />
    <field id="episode" type="string" />
    <field id="season" type="string" />
    <field id="airdate" type="string" />
    <field id="callsign" type="string" />
    </interface>
    </component>
  • I ended up using addFields, it does exactly what I need to do without the extra XML confusion. Works like a charm. Thanks all!