In most cases the result of <custom-resource>.query()
method is an array, which can be easily extended with some methods (business logics) with the following (factory) code:
var Data = $resource('http://..');
Data.prototype.foo = function() {return ...};
this is perfect for using with ng-repeat / ng-class, like so:
<tr ng-repeat="item in responseData" ng-class="{warning: item.foo()}">..</tr>
My problem is that every list response is encapsulated in an object which, besides the actual list, has some meta-properties (sorting info etc), so the final object returned is like this:
{ order_field: "name", items: [{..}, {..},{..}] }
Now, how do I make the same thing as previously with ng-repeat/ng-class?
<tr ng-repeat="item in responseData.items" ng-class="????">..</tr>
the previous method won't work as the "foo" method is defined on responseData
and NOT on item
object
Is there any way to directly extend the base class used for instantiating objects on the list?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…