knockout.js - Refreshing a navigation property in Breeze -
sorry if repeat going through documentation on breezejs.com , wanted see if bit of elaboration on 'best practice'
i using .extend load navigation properties on parent object. when want add entity observable array using modal pop-up. see blank entity added on view calls modal, when close modal after creating entity , saving observable array doesn't update , leaves main page's new entity blank.
http://www.breezejs.com/documentation/navigation-properties says using .push() observable array add object array wanted idea whether doing correctly or there better method. reason seems funny have return entity modal parent view , push it, , thought maybe there better method.
edit
from parent view model, use durandal.js's app.js show modal.
var addcomment = function () { rfcommentcreate.responseformid(responseform().id()); app.showmodal(rfcommentcreate).then(function (modalresult) { if (!modalresult) { datacontext.cancelchanges(); return false; } console.log(modalresult); // make sure result not null , of right type responseform.responseformresponseformcomments.push(modalresult); return true; }); }; when save on modal pass created object back.
datacontext.savechanges() .fail(initfailed) .fin(complete); function complete() { self.modal.close(responseformcomment()); // responseformcomment entity work on in modal } responseform.responseformresponseformcomments navigation property of responseform.
the above code adds entity breeze's entity manager knockout not tracking after created. appears true statement because in html on parent view see
: @
from html code
<span data-bind="text: user().fullname"></span> : <span data-bind="text: message"></span> @ <span data-bind="datetime: commentdt"></span> after create entity in modal
according navigation-properties page on breezejs.com should work if interpreting properly.
a: not, , fault b: there better method keeping track of navigation properties without having 'push' them array?
notice pushed orders , not orders().
there can timing issues ko. know it's kludgy might try following (btw, changed name of function parameter because modalresult not intuitive me):
app.showmodal(rfcommentcreate).then(function (comment) { if (!comment) { datacontext.cancelchanges(); return false; } console.log(comment); // make sure result not null , of right type responseform.responseformresponseformcomments.push(comment); return q.delay(true,5); // return true after 5 ms js event loop cycle in. }); my suggestion in last line:
return q.delay(true,5); // return true after 5 ms js event loop cycle in.
see q.delay method in q api reference. i'm doing giving ko chance hear event raised breeze's update of array , respond accordingly.
if there navigation responseformcomment responseform, don't think push navigation property (is called responseformresponseformcomments? "responseform" twice?), not there wrong that.
i'd rather write:
comment.responseform(responseform); // entity assignment
or
comment.responseformid(responseform.id); // foreign key assignment
both have intended side-effect of updating responseform's comments collection.
but main issue ... try delay , let know if works. ko , breeze timing mixed up.
Comments
Post a Comment