This is a migrated thread and some comments may be shown as answers.

What is Kendo doing to view model arrays?

3 Answers 165 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Brian Vallelunga
Top achievements
Rank 1
Brian Vallelunga asked on 23 May 2012, 09:16 PM
I have a view model with an array in it and don't seem to be able to use third party libraries such as Sugar to extend the functionality of the arrays. I've set up an example at http://jsfiddle.net/BrianVallelunga/rmgak/ 

It seems as though Kendo transforms the view model's fields into something completely different. Is there any way to still utilize libraries like Sugar in this situation?

If not, what type are the arrays transformed into, and what methods are available on them?

Thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 25 May 2012, 10:22 AM
Hi,

 Kendo MVVM wraps JavaScript array to a special ObservableArray type. This is required in order to track changes made to the array - adding or removing items. The ObservableArray does not inherit from the Array prototype (mainly because inheriting from Array does not work well among all browsers) hence it will not inherit any extensions by custom libraries. The observable array supports the common Array methods - push, pop, slice, splice etc.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brian Vallelunga
Top achievements
Rank 1
answered on 30 May 2012, 02:38 PM
Thanks. This makes sense, but it's a shame we can't use other libraries to enhance the ObservableArray.
0
Atanas Korchev
Telerik team
answered on 30 May 2012, 02:47 PM
Hello Brian,

 It should be possible to extend the ObservableArray:

kendo.data.ObservableArray.prototype.myMethod = function() {
     for (var i =0; i < this.length; i++) {
            var item = this[i];
     }
}


All the best,

Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
Brian Vallelunga
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Brian Vallelunga
Top achievements
Rank 1
Share this question
or