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

Calculated fields and parent()

1 Answer 101 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 15 Jul 2013, 10:23 PM
Hey,

I have an observable object looking something like this:

1.viewModel = kendo.observable({
2.    anArray: ['item1', 'item2', '...'],
3.    filteredArray: function() {
4.        return this.get('actions').filter(function (el) {
5.            return someLogic(el);
6.        });
7.    }
8.});
So far so good. No I want to use this filtered array in a source binding (to generate a table, say) and I want to to the following:

1.<script id="row-template" type="text/x-kendo-template">
2.    <tr>
3.        [...]
4.        <td><select data-bind="source: availableDescriptions, value: Description"/></td>
5.    </tr>
6.</script>
Where availableDescription is an array contained in my viewModel.
This generates an error (Uncaught TypeError: Object [object Array] has no method 'parent' )

Apparently kendo is resolving 'availableDescriptions' by calling 'parent()' on the observable array that is the context for my template. To work around this I changed my implementation of filteredArray to look like this:

1.filteredArray: function () {
2.    var a = this.get('actions').filter(function (el) {
3.        return doSomething(el);
4.    });
5.    a.parent = function () { return this; };
6.    return a;
7.}
It works, but isn't particularly graceful. Is there a better way to do this ?

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 17 Jul 2013, 11:40 AM
Hi Pierre,

It seems that this issue is addressed in the latest build. Please download Q2 official release (v2013.2.716) and give it a try.

For convenience I prepared a small sample:

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