Tutorial issue: Loading and saving data, Step 4 of 5

63 views
Skip to first unread message

Tamas Perger

unread,
Feb 11, 2016, 12:49:39 PM2/11/16
to KnockoutJS
I just noticed a tiny issue with the tutorial "Loading and saving data" - Step 4 of 5.
Using the proposed solution, I clicked the "Add" button without entering a text for the task, and then the "Save" button.
The response of the server: "Server received 4 task(s).", however, there are 5 items in the list.
I get this response even when I add several new items - as long as the first new item remains blank.

It seems that the first new task I create is represented as an empty object {}, however, all the following ones are created as {"title": ""}.
When the server processes the AJAX request, it probably stops processing the list at the first empty object.

I cannot fix the server side, however, the following code change resolves the problem (line 10 in ViewModel):
old: 
self.newTaskText ko.observable();
new:
self.newTaskText ko.observable("");

The problem occurs only with the first new task, as for the following tasks the initialization is performed inside the addTask function (line 18):
self.newTaskText("");

Thank you for the tutorial - it helps a lot and this minor issue does not diminish its value.

James

unread,
Jan 5, 2017, 4:32:58 PM1/5/17
to KnockoutJS
Thanks for posting this! Too bad they haven't changed the tutorial appropriately.
Reply all
Reply to author
Forward
0 new messages