繁体   English   中英

基因敲除.js observableArray计算值

[英]knockout.js observableArray computed value

情况:地址必须由用户输入,该条目查询数据库并提供建议。 选择现有值-设置现有ID。 新值-ID =0。如果是新条目,则会显示其他选择框。

通过select2设置ID,该值会正确更改。 计算值不(始终为假)。

<div data-bind="foreach: deliveryBuildings">
    <div>
        <input type="hidden" data-bind="value: buildingId, text: 'buildingName', select2: { minimumInputLength: 0, ajax: buildingAjax }" style="width: 200px; padding-top: 5px" />
        <div data-bind="visible: newBuilding">
             <input type="hidden" data-bind="value: regionId, select2: { minimumInputLength: 0, ajax: regionAjax }" style="width: 200px; padding-top: 5px" />
        </div>
    </div>
</div>


var DeliveryBuildingItem = function () {
    var self = this;
    self.buildingId = ko.observable();
    self.newBuilding = ko.computed(function () {
        return self.buildingId == '0' ? true : false;
    }, self);
}

var ViewModel = function () {
    var self = this;
    this.deliveryBuildings = ko.observableArray([new DeliveryBuildingItem()]);
}

使它成为self.buildingid()而不是self.buildingid

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM