angularjs - Angular 1/Javascript - alternative to lodash omit and delete operator -
i have child component have delete properties object.
normally using lodash should work code :
this.current.obj = omit(this.current.obj, ['sellersupportweb', 'sellersupportagency', 'sellersupportagent'])
just current.obj model not mount parent component
but if delete properties object operator delete
works
delete this.current.obj.sellersupportagency delete this.current.obj.sellersupportweb delete this.current.obj.sellersupportagent
is there not alternative same job delete , omit ?
i not know if can help, work omit i'm calling parent object (parent component) on child component on it, i'm looking solution since current.obj
for (const [index] of this.current.parent.items.entries()) { this.current.parent.items[index] = omit(this.current.parent.items[index], ['sellersupportweb', 'sellersupportagency', 'sellersupportagent']) }
if understand correctly, want modify object shared between component , parent. object in array in parent component, assume using ng-repeat
statement. i'm not sure, because didn't share component definition nor instantiation in parent component template.
when change local object reference (with omit
), array in parent component not modified. when change local object in place (with delete), local variable still reference object in parent array, , modified in both places (since same object).
long story short, have choose between modifying array (in parent), or removing fields local object (and delete
way that). former more angular-like, if use '&'-type event handlers tell parent component want fields removed object. this:
angular.component(... bindings: { filterobjecthandler: '&onfilterobject' (...) this.filterobjecthandler(['sellersupportweb', 'sellersupportagency', 'sellersupportagent']);
or that. there interesting set of articles here component structure in angularjs 1.5+.
however, if want way delete fields in way involving one-liner array of fields, use this:
var obj = this.current.obj; ['sellersupportweb', 'sellersupportagency', 'sellersupportagent'].foreach(function(field) { delete obj[field]; });
or even:
['sellersupportweb', 'sellersupportagency', 'sellersupportagent'].reduce(function(obj, field) { delete obj[field]; return obj; }, this.current.obj);
wiki
Comments
Post a Comment