Hello,

I'm learning node.js+knockout.js+mongodb programming now.
As an initial target I set myself the goal to write a node.js back-end to 
the last lesson in knockout's interactive tutorial, which is a task-list 
app: http://learn.knockoutjs.com/#/?tutorial=loadingsaving

I manage to serve the static files and get the JSON data sent to the 
"/tasks" URL path when the "save" button is pressed.

The task list is sent as a JSON array, naturally. When an entry is marked 
to be deleted it is sent to the server with an additional "_destroy: true" 
attribute, e.g. after the "wake up yoyo" task at the end of the list is 
delete, this is the JSON I get:

{"tasks":[{"title":"Wire the money to Panama","isDone":true},{"title":"Get 
hair dye, beard trimmer, dark glasses and 
\"passport\"","isDone":false},{"title":"Book taxi to 
airport","isDone":false},{"title":"Arrange for someone to look after the 
cat","isDone":false},{"title":"wake up 
yoyo","isDone":true,"_destroy":true}]}

My question - what's the most recommended, "best practice" way to process 
it? Should I just something like:

tasks.forEach(function(task) {
  if (task._destroy) {
    // delete from mongodb
  } else {
    // add to mongodb
  };
});

Or is there a more elegant way? Is there some node.js or even a 
mongonode-specific way to just copy JSON to and from mongodb instead of 
manually iterating over the data on each request?

In general - is _destroy a standard convention or is it unique to 
knockout.js? (I'm going to ask this one also on the KO Google Group).

Thanks,

--Amos

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to