Sorry if this is a repeat but I was going through the documentation on Breezejs.com and I wanted to see if I could get a bit of an elaboration on 'best practice'
I am using .extend to load up some navigation properties on a parent object. When I want to add an entity to that observable array I am using a modal pop-up. I see the blank entity added on my view that calls the modal, but when I close the modal after creating the entity and saving the observable array doesn't update and just leaves the main page's new entity blank.
http://www.breezejs.com/documentation/navigation-properties says that using .push() into the Observable array will add the object to the array so just wanted to get an idea whether I am doing this correctly or there is a better method. The reason it seems funny is that I have to return the entity from my modal back to my parent view and then push it, and thought maybe there was a better method.
Edit
From my parent view model, I use Durandal.js's app.js to show a modal.
var addComment = function () {
rfcommentcreate.responseFormId(responseForm().id());
app.showModal(rfcommentcreate).then(function (modalResult) {
if (!modalResult) { datacontext.cancelChanges(); return false; }
console.log(modalResult); // Just to make sure the result is not null and of the right type
responseForm.responseFormResponseFormComments.push(modalResult);
return true;
});
};
When I save on the modal I pass the created object back.
datacontext.saveChanges()
.fail(initFailed)
.fin(complete);
function complete() {
self.modal.close(responseFormComment()); // responseFormComment is the entity that I work on in the modal
}
ResponseForm.ResponseFormResponseFormComments is the navigation property of ResponseForm.
The above code adds the entity to Breeze's entity manager but Knockout is not tracking it after it is created. This appears to be a true statement because in my Html on the parent view I see something like this
: @
from the HTML code
<span data-bind="text: user().fullName"></span> : <span data-bind="text: message"></span> @ <span data-bind="DateTime: commentDt"></span>
After I create the entity in the modal
According to the navigation-properties page on breezejs.com that should work if I am interpreting it properly.
A: It does not, and is probably my fault B: Is there a better method to keeping track of navigation properties without having to 'push' them into an array?
Notice that we pushed to Orders and not Orders().