我只是想尝试使用asp.net母版页进行淘汰赛。在母版页中,我有jquery和knockout的脚本引用。在示例内容页面中,我有以下内容,但选择控件永远不会被填充。我错过了什么?
<asp:content id="Content1" contentplaceholderid="contentBody" runat="server">
<select data-bind="options: docTypes ,
optionsCaption: 'Choose document type',
optionsText: 'name',
value: chosenDocType"></select>
<script>
$(function(){
function emailViewModel() {
this.docTypes = [
{ name: "1" },
{ name: "2" },
{ name: "3" }
];
this.chosenDocType = ko.observable();
}
ko.applyBindings(emailViewModel);
});
</script>
</asp:content>
答案 0 :(得分:2)
您没有实例化emailViewModel
更改
ko.applyBindings(emailViewModel);
到这个
ko.applyBindings(new emailViewModel());
小提琴here