简体   繁体   中英

Knockout containerless control flow syntax foreach misses binding update

I am trying to use Knockout.js to build a simple CRUD table where you can list the maintenance history of a vehicle.

Everything is working except of one thing: when I POST the item over to the server and I receive a 200 OK response, I make it like in the UI you're not anymore available to fill in the inputs, but that does not work.

The item always stays in "creation mode".

Here's a JSFiddle of the code.

Here's where the stuff happens:

[...]

self.store = function () {
    if (! self.creation) return;
    console.log('stored in theory!!!!!');
    self.creation = false;
}

[...]

Note: All AJAX requests have been removed from the JSFiddle for demonstration / easier debugging purposes.

Solved.

Every single declaration of creation variable needed to be transformed to a ko.observable() .

self.creation = ko.observable(false);
self.creation(false);
self.creation(true);

// instead of...

self.creation = false;
self.creation = false;
self.creation = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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