javascript - Breeze Many to Many relationship and setting Aspect to 'setDeleted' on iteration issue -
my goal save user selection on multi-selected list kendouiweb-multiselect. felt easiest way keep track of changes list delete many many relationship , add newly selected items. when iterate through many many relationship , set each entity's aspect 'setdeleted' iteration begins pass 'undefined' objects through loop. on surface, seems setting conjunction object delete affecting other objects in list within breeze. there way can delete conjunction objects iteratively?
to note: can iterate through conjunction model no issue if don't call method..
public class course { public int id { get;set; } public string name { get;set; } } public class student { public int id { get; set; } public string name { get; set; } } public class studentcourse { public int studentid { get;set; } public virtual student student { get;set; } public int courseid { get;set; } public virtual course course { get;set; } } the following code works (sets multi-selected dropdown kendoui multiselect):
var getselectedcourses = function () { var selected = []; ko.utils.arrayforeach(student().studentcourses(), function(course) { var courseid = parseint(course.courseid()); selected.push(courseid); }); return selected; }; the issue manifested following code. first couple of iterations seem go through fine after 'undefined' passed 'course' parameter
var removelistitems = function () { if (coursehaschanges()) { //remove list items ko.utils.arrayforeach(student().studentcourses(), function(studentcourse) { if (studentcourse) { //passing undefined after 2nd or 3rd iteration studentcourse.entityaspect.setdeleted(); } }); } };
i believe breeze removing course studentcourses() array iterating through calling setdeleted().
perhaps using slice(0) clone original studentcourses() array might work: (not tested)
var removelistitems = function () { if (coursehaschanges()) { //remove list items ko.utils.arrayforeach(student().studentcourses().slice(0), function(course) { if (course) { //passing undefined after 2nd or 3rd iteration course.entityaspect.setdeleted(); } }); } };
Comments
Post a Comment