0

Right now I have a list of view models displayed in a table that has an edit template. This is great for doing small changes, but only certain properties are exposed to that table. I want to be able to have a user be allowed to edit the record in a standalone view just for editing that can contain more information (right now I am just expanding the table row for each record into a HUGE tr element, which is pretty messy).

I assume I want to do something as suggested in this solution: Using KnockoutJS with multiple pages

Where they are applying bindings to a single dom element, such as an edit view...

Where I'm most confused is if I am doing something like:

ko.applyBindings(
editModelViewModel, 
document.getElementById('editView')
);

Do I just keep a record in my main view model named editModelViewModel and switch out the model with whatever is being edited at the time, am I supposed to somehow clear the applied bindings every time I want to switch to this edit view, or is there a different way altogether to accomplish building a standalone edit page for a model in knockout.js?

It should be noted that I'm using sammy.js as my routing, so I figure that my route for editing would be something like:

#/editObject/:id
Community
  • 1
  • 1
jyanks
  • 2,356
  • 1
  • 19
  • 36

1 Answers1

1

What if the model included all the data for both modes? The view could then choose which values to expose. If you wanted to just have one view, you might even have a flag that sets whether or not the view is in edit mode. Then, all the router has to do is set that flag.

Ryan DeBeasi
  • 256
  • 1
  • 6