Lets say I have 1 GET request and from it i get an array of objects. Is there any way to make a dropdown of all the objects so i can manually select which object I want to use?
You can send options to dropdown
node using msg.options
.
[{"id":"2e20d61f.4aa97a","type":"ui_dropdown","z":"78abef.11f5941","name":"","label":"Dynamic Options","tooltip":"","place":"Select option","group":"346f3afd.14dd56","order":0,"width":0,"height":0,"passthru":true,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","x":710,"y":460,"wires":[[]]},{"id":"bca9b0ae.b6384","type":"inject","z":"78abef.11f5941","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":460,"wires":[["5d2ee77f.a8fe38"]]},{"id":"5d2ee77f.a8fe38","type":"function","z":"78abef.11f5941","name":"","func":"\nvar pl = [\n {\n \"one\":{\n \"param\":1,\n \"data\":123\n }\n },\n {\n \"two\":{\n \"param\":1,\n \"data\":123\n }\n },\n {\n \"three\":{\n \"param\":1,\n \"data\":123\n }\n }\n]\nmsg.options = pl\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":540,"y":460,"wires":[["2e20d61f.4aa97a"]]},{"id":"346f3afd.14dd56","type":"ui_group","name":"Default","tab":"445e350b.bd700c","order":1,"disp":true,"width":"6","collapse":false},{"id":"445e350b.bd700c","type":"ui_tab","name":"Home","icon":"dashboard","order":6,"disabled":false,"hidden":false}]
See also at the node-s help page.
You didn't understand me. I know about the dropdown UI node. Im wondering if it can be an function node so i can select whatever data I get from HTTP request
If what can be a function node?
Imagine u have http request from which u get an array of objects. I want my dropdown node to show those objects ( as options in Select html tag ) and let me choose which 1 i want to output.
Did you read the help text for the dropdown node as suggested by @hotNipi? In particular it says
" The Options may be configured by inputting msg.options
containing an array. If just text then the value will be the same as the label, otherwise you can specify both by using an object of "label":"value"
pairs :
[ "Choice 1", "Choice 2", {"Choice 3":"3"} ]
".
Did you try the flow he posted? It shows exactly what you want to do, unless I still don't understand what you want.
Its hard to explain because i dont exactly know how but let me try 1 more time. I dont need the UI (Dashboard dropdown node). I need for example a custom node that will have the select tag filled with options which are the objects i recive from the array.I think i cant explain it any better , anyways thank you.
Do you mean that you run the flow, the response comes and you feed it to the node which take the input and stores those values as config options which you can choose from dropdown? Or you want the node which provides the dropdown at the editor directly so you can change the choice of option on fly?
For me it seems that both are kind of against the conception what the node should do but who knows ...
What is the difference between that and the dashboard dropdown node?
The first one yeah.
The usual way would be for your custom node to do its own request (or fetch) and then populate its own drop down, so it is all self contain.
You shouldn’t expect live flow data to populate the editor options.
I actually managed to do quite a lot. All i need now is to know if and how can I access msg.payload in html file .
Do you mean when the HTML file is running in the browser or do you mean you want to insert the payload into the html before it is sent to the browser?
The answer to the former is no, the latter yes.
Tried using the get method insidte of the node and i get back an Array that has 1 Array inside that is full of objects. How do i access those objects. My variable that holds that array is called opt. I tried opt[0].name or opt[0][0].name but nothing seems to work.
Read the node-red doc page Working with Messages which shows you how to get the path to a property from the debug pane.
I get a strange problem. So the data i get from http request is an array.I push the data in and existing array called opt and when i type opt.length the result is 0. But in my console i can see an array full of objects.Any idea why that happens?
I can't, sorry, my psychic abilities are on the fritz.
But seriously, could you answer a question like that with so little detail, no code, no screenshots, no sample data?
Give us something to go on
I get an array full of objects but i cant access it.
Looks like what you are seeing is due to async nature of that code. The console.log is probably being called before the promise has resolved (before then
is called)
Put the log inside the then
See, details help