knockout.js observableArray computed value

user3047656

Situation: Address must be entered by user, the entry queries the database and provides suggestions. Selects existing value - sets existing ID. New value - ID = 0. If it's a new entry, additional selection box is shown.

The id is set via select2, the value changes correctly. Computed value does not (always false).

<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()]);
}
PW Kad

Make it self.buildingid() instead of self.buildingid inside the computed

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

knockout.js: No concat on observableArray

From Dev

Knockout.js - Registering to change in observableArray

From Dev

Knockout JS - Modifying properties of items in observableArray

From Dev

Knockout js computed running balance infinite loops

From Dev

Knockout js Computed not being fired

From Dev

Knockout computed observable with access to observableArray

From Dev

knockout foreach computed value

From Dev

Knockout Modifying ObservableArray inside Computed

From Dev

Knockout.js contenteditable observablearray

From Dev

How to bind checkbox value to Knockout observableArray on an object?

From Dev

Custom filtering knockout js observableArray

From Dev

Knockout Js computed not working in a model

From Dev

Put computed value inside progress bar Knockout js

From Dev

Knockout JS Error: Cannot write a value to a ko.computed unless you specify a 'write' option

From Dev

knockout.js: No concat on observableArray

From Dev

Knockout.js - Registering to change in observableArray

From Dev

knockout.js observableArray changes not reflecting in UI

From Dev

Knockout js Computed not being fired

From Dev

Knockout add CSS class depending on value in observableArray

From Dev

knockout foreach computed value

From Dev

Update ObservableArray - Knockout.js

From Dev

Knockout Computed - write a new value

From Dev

Knockout Modifying ObservableArray inside Computed

From Dev

Knockout update computed value after blur

From Dev

Knockout JS failed to update observableArray

From Dev

Knockout observableArray not updating all properties on checked value

From Dev

Knockout js observableArray is not getting updated

From Dev

Knockout observableArray not being populated by inherited datepicker value

From Dev

Sorting observableArray with added item Knockout JS

Related Related

  1. 1

    knockout.js: No concat on observableArray

  2. 2

    Knockout.js - Registering to change in observableArray

  3. 3

    Knockout JS - Modifying properties of items in observableArray

  4. 4

    Knockout js computed running balance infinite loops

  5. 5

    Knockout js Computed not being fired

  6. 6

    Knockout computed observable with access to observableArray

  7. 7

    knockout foreach computed value

  8. 8

    Knockout Modifying ObservableArray inside Computed

  9. 9

    Knockout.js contenteditable observablearray

  10. 10

    How to bind checkbox value to Knockout observableArray on an object?

  11. 11

    Custom filtering knockout js observableArray

  12. 12

    Knockout Js computed not working in a model

  13. 13

    Put computed value inside progress bar Knockout js

  14. 14

    Knockout JS Error: Cannot write a value to a ko.computed unless you specify a 'write' option

  15. 15

    knockout.js: No concat on observableArray

  16. 16

    Knockout.js - Registering to change in observableArray

  17. 17

    knockout.js observableArray changes not reflecting in UI

  18. 18

    Knockout js Computed not being fired

  19. 19

    Knockout add CSS class depending on value in observableArray

  20. 20

    knockout foreach computed value

  21. 21

    Update ObservableArray - Knockout.js

  22. 22

    Knockout Computed - write a new value

  23. 23

    Knockout Modifying ObservableArray inside Computed

  24. 24

    Knockout update computed value after blur

  25. 25

    Knockout JS failed to update observableArray

  26. 26

    Knockout observableArray not updating all properties on checked value

  27. 27

    Knockout js observableArray is not getting updated

  28. 28

    Knockout observableArray not being populated by inherited datepicker value

  29. 29

    Sorting observableArray with added item Knockout JS

HotTag

Archive