How can I create a default property like array?

#1

Hi,

I try to set an array var to store some objects in a node, something like that:

In the image, Atributos is an array with 3 objects, but I can't use this variable in the js file.

Thanks!

0 Likes

#2

That is not one of the core nodes I recognise. Which node is that ?
As it's not a core node you may need to contact the author of the node directly and ask them to add to their docs.

0 Likes

#3

It's a custom node that I'm developing. It's a node that create an entity in Orion Context Broker, and I need an array with the attributes of the entity.

Thanks!

0 Likes

#4

Ah.. - you will need to build the array into a default property during the oneditsave function and pass it back that way (and vice versa you will need to take the saved version from that property and re-populate the ui during oneditprepare

0 Likes

#5

Are oneditsave and oneditprepare functions for js file? I try it, but I have the info in the form and it isn't accessible for js file.

Thanks!

0 Likes

#6

they are javascript functions in the html file - see the docs - https://nodered.org/docs/creating-nodes/node-html. Once you have manipulated them into a property defined in the defaults list (eg a hidden field node-input-myArray as myArray in the defaults list), then they will be available in the config on the js side.

0 Likes

#7

Ok, I can define in the defaults like that?:

defaults: {
myArray: { value: new Array()}
}

0 Likes

#8

I would go for myArray: { value: [] }

0 Likes

#9

I try something like that

RED.nodes.registerType('fiware-in', {
        category: 'Fiware',
        color: '#a6bbcf',
        defaults:{
            name: {value:""},
            fiware_action: {value:"", require:true},
            fiware_host: {value:"", requite:true},
            fiware_entity: {value:"", require:true},
            fiware_attrs_array: {value:[]},
            fiware_options_json: {value:"", require:true}
        },
        inputs:0,
        outputs:1,

And then, in the html:

<div class="form-attr">
            <label for="node-input-fiware_attrs_array"><i class="icon-tag"></i> Atributos </label>
            <input type="text" id="attr_name_1" placeholder="Name">
            <input type="text" id="attr_type_1" placeholder="Type">
            <input type="text" id="attr_value_1" placeholder="Value">
            <div id="addAttr" class="form-row"></div>
            <br>
            <input type="button" name="button_add" value="Añadir atributo" onclick="addAttr()">
            <input type="button" name="button_remove" value="Borrar último atributo" onclick="removeAttr()">
            <br>
            <input type="button" name="button_validate" value="Validar atributos" onclick="validate()">
        </div>

The validate button, copy an array with each attribute in fiware_attrs_array. But when I try to receive those data in the js file, I have an empty array

0 Likes