0

I am trying to set the values for a popup menu in Dashcode programmatically. I can change the text/value of some statically defined default ones (from the inspector), but not add or remove them. When the view is initialised it must take a variable number of options.

    var popup = document.getElementById('popup');
    //popup.options = []; /* Doesn't clear the list */
    //popup.options.length = 0; /* Doesn't clear the list */
    popup.options[0].text = "Option 1";
    popup.options[0].value = "123";

How can I modify the list? (LMGTFY answers not required :)

4

3 に答える 3

1

私は最終的にこのように解決しました:

//remove all
if (popup.hasChildNodes()) {
    while (popup.childNodes.length >= 1) {
        popup.removeChild(popup.firstChild);       
    }
}

//add new
$.each(items, function(i, item) {
    var option = document.createElement("option");
    option.text = item.name;
    option.value = item.id;
    popup.appendChild(option);      
});
于 2010-01-29T11:07:19.337 に答える
0

ただの刺し傷ですが、JavaScriptでポップアップ全体を作成し、パラメーターを渡してドロップダウン/ポップアップの項目数を設定することはできませんでした。次に、アイテムのいずれかを変更したい場合は、新しいパラメーターを使用してJavaScriptを呼び出すことができますか?

または私は質問を誤解しましたか。

于 2010-01-28T14:20:20.983 に答える
0

あなたと同じようにポップアップメニュー項目を動的にバインドしようとすると、ポップアップメニュー項目に割り当てる値が正しいことがわかりますが、ポップアップに表示される項目はありません。

私が欠けているものはありますか?これが私のコードです:

var ddlCurrencyCode = document.getElementById('ddlCurrencyCode'); if (ddlCurrencyCode.hasChildNodes()) { while (ddlCurrencyCode.childNodes.length >= 1) { ddlCurrencyCode.removeChild(ddlCurrencyCode.firstChild);
} }

for (var i = 0; i < result.rows.length; ++i) { var row = result.rows.item(i);
var ddlItem = document.createElement("ddlItem"); ddlItem.text = 行['キー']; ddlItem.value = 行['値']; ddlCurrencyCode.appendChild(ddlItem);
}

于 2010-04-29T16:59:44.803 に答える