The splunk web framework provides a dropdown view component which I populate with choices before rendering:
var menu = new DropdownView({
id: "split_categories_" + idx,
choices: opts_to_choices(opts),
default: "Usage",
showClearButton: false,
el: $(this)
}).render();
The documentation:
http://docs.splunk.com/DocumentationStatic/WebFramework/1.0/compref_dropdown.html
Provides info about listening to on-change events, setting choices, and rendering, but doesn't mention anything about changing the choices that appear in the dropdown menu.
If you analyse the structure of the menu
object after rendering, you can see that choices are stored inside the options
child object. None of the following correctly updates the choices:
menu.choices
to a new valuemenu.choices
to a new value and re-renderingmenu.options.choices
to a new valuemenu.options.choices
to a new value and re-renderingIf you take a look at the views source (which I'm not even sure is relevant or not),
https://github.com/splunk/splunk-webframework/blob/master/server/static/splunkjs/compiled/views.js
You might be led to believe that:
menu.el.innerHTML = ""
might cause menu.render()
to work againmenu.setItems()
on a new object might be the correct way to change choicesNeither of these works either.
So what's the correct way to re-render the view?
The 1.0 reference is outdated. If you manually change the reference URL from 1.0
to 1.2
, you'll get the following updated reference:
http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/compref_dropdown.html
Here, you can see that menu.settings.set("choices", [])
is the correct way to change the choices in a dropdown view.
Sadly, the default google result finds web framework @ 1.0, and the 1.0 docs don't have any reference to the 1.2 docs.
The 1.0 reference is outdated. If you manually change the reference URL from 1.0
to 1.2
, you'll get the following updated reference:
http://docs.splunk.com/DocumentationStatic/WebFramework/1.2/compref_dropdown.html
Here, you can see that menu.settings.set("choices", [])
is the correct way to change the choices in a dropdown view.
Sadly, the default google result finds web framework @ 1.0, and the 1.0 docs don't have any reference to the 1.2 docs.