假设我有以下 Javascript:
var Option = (function ()
{
function Option(value, text)
{
this.value = value;
this.text = text;
}
return Option;
})();
var QuestionTypes = (function ()
{
QuestionTypes.chooseOne = new Option("ChooseOne", "Choose One");
QuestionTypes.chooseMany = new Option("ChooseMany", "Choose Many");
QuestionTypes.text = new Option("Text", "Text");
QuestionTypes.all = function ()
{
return
[
QuestionTypes.chooseOne,
QuestionTypes.chooseMany,
QuestionTypes.text
];
};
return QuestionTypes;
})();
这个HTML:
<select data-bind="value: type, options: QuestionTypes.all, optionsValue: value, optionsText: text" />
所以select
绑定到我的“静态”变量QuestionTypes
。我希望结果select
看起来像这样:
<select data-bind="value: type, options: QuestionTypes.all, optionsValue: value, optionsText: text">
<option value="ChooseOne">Choose One</option>
<option value="ChooseMany">Choose Many</option>
<option value="Text">Text</option>
</select>
基本上,我如何绑定到全局而不是模型本身的东西?