Knockout.js 无法计算简单的helloworld敲除示例

Knockout.js 无法计算简单的helloworld敲除示例,knockout.js,Knockout.js,我试图使用knockout,但是尽管代码非常简单,我还是无法填充选择列表。 下面是代码,谁能指出我做错了什么 <html> <head> <script type="text/javascript" src="knockout-3.3.0.js"> </head> <body> <script type="text/javascript"> var listEditorViewModel =

我试图使用knockout,但是尽管代码非常简单,我还是无法填充选择列表。 下面是代码,谁能指出我做错了什么

<html>
<head>
    <script type="text/javascript" src="knockout-3.3.0.js">
</head>
<body>
    <script type="text/javascript">
        var listEditorViewModel = function () {
        this.allItems = ko.observableArray(["Apple"]);
        }
        ko.applyBindings(document.body,new listEditorViewModel());
    </script>
    <div>This Select will be populated</div>
    <select multiple="multiple" data-bind="options: allItems"></select>
</body>
</html>

var listEditorViewModel=函数(){
this.allItems=ko.observearray([“苹果]);
}
applyBindings(document.body,newlisteditorViewModel());
此选择将被填充

您在
applyBindings
中的参数顺序不正确-第一个参数必须是model,第二个参数是DOM元素。按如下方式更新代码:

ko.applyBindings(new listEditorViewModel(), document.body);
或者忽略第二个参数,因为您仍要绑定到所有文档:

ko.applyBindings(new listEditorViewModel());