I've been following the simple editor pattern on knockmeout and everything worked as expected until I started using nested objects.
Basically when I select an item I'm setting 2 properties on my viewmodel. A selectedItem
property and an editable
property. It's the editable property that I then make changes to. If the user accepts the changes then the selected item is updated.
This works fine in my code if I have a flat object. However when I have nested objects the child objects data is not correct when assigned to the editable property.
I should see:
"Selected": {
"Id": 1,
"Name": "user 1",
"Role": {
"Id": 2,
"RoleName": "IT Support"
}
},
"Editable": {
"Id": 1,
"Name": "user 1",
"Role": {
"Id": 2,
"RoleName": "IT Support"
}
However I get:
"Selected": {
"Id": 2,
"Name": "user 1",
"Role": {
"Id": 3,
"RoleName": "IT Procurement"
}
},
"Editable": {
"Id": 2,
"Name": "user 1",
"Role": {
"Id": 2,
"RoleName": "IT Support"
}
If I log the details object passed to the selectItem method I can see the data is correct. It just doesn't seem to be correct when assigned to the editable property.
Apologies if this isn't very clear. Here is a link to my fiddle