I'm not sure if I correctly understood your question (maybe you provide a
plnkr?),
but if you are asking "Is it a good idea to iterate over the properties of
an Object?",
I can certainly say that is OK
Cheers
On Thursday, 15 May 2014 01:41:30 UTC+2, Eric Eslinger wrote:
>
> Short question: if I have an ng-repeat set up where the underlying
> collection is a plain object rather than an array, things still mostly work
> (except for sorting, for some reason). I'm wondering if this is intended /
> supported, or if I'm relying on a bug. Follow-up question is, how does one
> get that to work with filters and sorts, as they don't seem to work quite
> right.
>
> Longer version of the question:
>
> My specific issue is that my api objects have large-ish lists of related
> objects, and that list can change over time (e.g., comments on a forum
> post). Ideally, I'd be able to apply these changes without invalidating the
> existing collection. So instead of doing $http.get().then (data)->
> @relatedList = data.values, I'd *way* rather only append to the end of the
> list new entries in said list. My initial inclination is to just iterate
> over data.values and say @relatedList[value.id] = value, ending up with
> an object which is array-esque {1: {id: 1, ...}, 4: {id: 4, ...} ...},
> instead of [, [id:1...], , , [id: 4...] ...] getting created in the case
> where relatedList is initialized as [] instead of {}
>
> tangential - I'm relatively new to javascript, so I don't actually know if
> having a very large sparse array is actually all that bad.
>
> The other alternative is to just use something like Array.some on the
> relatedList like @relatedList.push(value) unless @relatedList.some (v)->
> v.id == value.id
>
> That strikes me a bit expensive for these kinds of updates. Then again,
> maybe it's no big deal - my @relatedList is probably only going to average
> in the 20-50 range for most cases. So, maybe I'm doing premature
> optimization.
>
> Anybody have any thoughts on this?
>
> e
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.