Javascript 为什么在敲除js中的observableArray中添加项目后我的UI不更新?

Javascript 为什么在敲除js中的observableArray中添加项目后我的UI不更新?,javascript,jquery,knockout.js,Javascript,Jquery,Knockout.js,我是击倒js的新手。我正在努力学习。作为我的学习过程,我制作了一个示例程序。但我在ObservalArray中添加新项目时遇到了一个问题。我可以在ObservalArray中成功添加项目,但添加后,它不会在我的选择中显示任何文本。但增加了一项。单击该项目时,所有信息都显示在下面 我的HTML: <div id="contener"> <div id="productListView"> <select multiple="multiple"

我是击倒js的新手。我正在努力学习。作为我的学习过程,我制作了一个示例程序。但我在ObservalArray中添加新项目时遇到了一个问题。我可以在ObservalArray中成功添加项目,但添加后,它不会在我的选择中显示任何文本。但增加了一项。单击该项目时,所有信息都显示在下面

我的HTML:

<div id="contener">
    <div id="productListView">
        <select multiple="multiple" id="MyproductListView" size="10" style="min-width: 120px;" data-bind="options: productCollection, value: listViewSelectedItem, optionsText: 'description'"></select>
    </div>
    <div id="productView" data-bind="with: selectedProduct">
        <p>
            SKU: <span data-bind="text: sku"></span>
        </p>
        <p>
            Description: <span data-bind="text: description"></span>
        </p>
        <p>
            SKU: <span data-bind="text: price"></span>
        </p>
        <p>
            Description: <span data-bind="text: cost"></span>
        </p>
        <p>
            Description: <span data-bind="text: quantity"></span>
        </p>
    </div>
    <div id="NewProduct" data-bind="with: selectedProduct">
        <form>
            <fieldset>
                <legend>Product Details</legend>

                <label>SKU :
                    <input type="text" data-bind="value:sku" /></label>

                <br />
                <label>Description :
                    <input type="text" data-bind="value:description" /></label>

                <br />
                <label>Price :
                    <input type="text" data-bind="value:price" /></label>

                <br />
                <label>Cost :
                    <input type="text" data-bind="value:cost" /></label>

                <br />
                <label>Quantity :
                    <input type="text" data-bind="value:quantity" /></label>
            </fieldset>
        </form>
    </div>
    <div id="buttonContainer">
        <button type="button" data-bind="click:addNewProduct">Add</button>
        <button type="button" data-bind="click:RemoveProduct">Remove</button>
        <button type="button" data-bind="click:DoneEditingProduct">Done</button>
    </div>
</div>
我已经用了3天的时间搜索了很多,但我无法探究为什么它没有更新

我一定要做错事

更新:

我的小提琴代码:

您正在引用父对象 函数乘积(){ self.sku=ko.可观察(“”)

换成

function product() {
        this.sku = ko.observable("");

        this.description = ko.observable("");

        this.price = ko.observable(0.00);

        this.cost = ko.observable(0.00);

        this.quantity = ko.observable(0);
    }

更新了上面的fiddle。

你能创建一个再现你的问题的JSFIDLE吗?这里有很多代码。你能指出什么没有按预期工作吗?如果你不把所有东西都扔给我们,帮助会容易得多。将
var self=this;
移到
函数产品()中{
这将起作用…投票结束太本地化。。。
        self.description = ko.observable("");

        self.price = ko.observable(0.00);

        self.cost = ko.observable(0.00);

        self.quantity = ko.observable(0);
    }
function product() {
        this.sku = ko.observable("");

        this.description = ko.observable("");

        this.price = ko.observable(0.00);

        this.cost = ko.observable(0.00);

        this.quantity = ko.observable(0);
    }