デフォルトのオプションセットを備えたhtml選択入力があります(IDがあります)。次のようなjsonオブジェクトもあります
var replacement_options = {'value 1':'display 1', 'value 2':'display 2' ....
Facebook JS を使用して、select のオプションを json オブジェクトの値と表示に置き換えるにはどうすればよいですか? (FBJS)
デフォルトのオプションセットを備えたhtml選択入力があります(IDがあります)。次のようなjsonオブジェクトもあります
var replacement_options = {'value 1':'display 1', 'value 2':'display 2' ....
Facebook JS を使用して、select のオプションを json オブジェクトの値と表示に置き換えるにはどうすればよいですか? (FBJS)
いくつかのものをつなぎ合わせた後、これを行う関数を作成することができました。
//accepts a object for options {value1:display1, value2:display2...
function updateSelectOptionsWithJSON(element_id, options, first_display, first_value)
{
var choiceList = document.getElementById(element_id);
for(var count = choiceList.getOptions().length - 1; count > -1; count--)
{
var node = choiceList.getOptions()[count];
choiceList.removeChild(node);
}
//you can remove these next 4 lines and the last two parameters of this function
//if you just want options to come from the secton parameter
var node = document.createElement('option');
node.setTextValue(first_display);
node.setValue(first_value);
choiceList.appendChild(node);
for(key in options)
{
var node = document.createElement('option');
node.setTextValue(options[key]);
node.setValue(key);
choiceList.appendChild(node);
}
}
selectNode.removeChild
FBJS wiki エントリFBJSで説明されている FBJS 関数で遊んでみてください。
また、使用する必要があります
var option = document.createElement('option');
selectNode.appendChild(option);
選択ノード内にオプション ノードを作成するには