javascript - Enumerate subclassed array in ngRepeat -
i want reusable list own custom behaviors (e.g. updateorappendbyitemid
) hold retrieved array enumeration via ngrepeat
. main purpose hold live collections - contents might changed locally or remotely (via signalr). should:
- enumerate in
ng-repeat
directive - not render custom behaviors items (rows)
- retain sort order de-serialized source
- behave across modern browsers
- avoid unnecessary list copying
how should constructed?
i've run conceptual problems when building few different ways. javascript array
can't subclassed. copying behavioral prototype directly array
instance results in undesired enumerable properties. storing contents in object properties loses source item order.
each of problems has theoretical severity me, real-world consequences depend on both undocumented angularjs behavior , browser differences. i'm hoping has touched problem before can save me lots of trial-and-error.
research:
since i'm starting potentially lengthy investigation hoping avoid, i'll post work here.
angular's ngrepeat
first tests if collection isarraylike()
. if is, iterates through length of collection numerically. seems highly intentional (although wouldn't want depend on interpretation of internal function isarraylike()
).
in 1 browser tested in far, neither of following change effective array contents.
// safe array.mymethod = true; array['mymethod'] = true;
however, following disastrous: /grin
array['5'] = true;
so, that's ecma spec:
a property name p (in form of string value) array index if , if tostring(touint32(p)) equal p , touint32(p) not equal 232−1.
i may not have go further. i'll try solution , report back.
Comments
Post a Comment