淘汰赛每一场比赛都没有表现出任何东西

Knockout foreach won't show anything

本文关键字:任何东 一场 淘汰赛      更新时间:2023-09-26

我是淘汰赛的新手,当我想使用foreach时,我只得到1个空行,而我的数组中有2个对象?

这是我的HTML代码

    <tbody data-bind="foreach: lijst">
    <tr>
        <td><input type="text" data-bind="value: naam"/></td>
        <td><input type="number" data-bind="value: aantal"/></td>
    </tr>
    </tbody>
function Product(naam, aantal) {
    var self = this;
    self.naam = naam;
    self.aantal = aantal;
}
function komaan() {
    var self = this;
    self.lijst = ko.observableArray([
        new Product("Flesje Tonic", 6),
        new Product("Gin", 6)
    ]);
}
ko.applyBindings(new komaan());

很可能你的knockout js库没有正确加载。

这是一个在线示例,您的代码按预期工作http://jsfiddle.net/wyeegtaL/1/

function Product(naam, aantal) {
    var self = this;
    self.naam = naam;
    self.aantal = aantal;
}
function komaan() {
    var self = this;
    self.lijst = ko.observableArray([
        new Product("Flesje Tonic", 6),
        new Product("Gin", 6)
    ]);
}
ko.applyBindings(new komaan());
相关文章: