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

undefined is not a function on unbinding a viewmodel

3 Answers 296 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 30 Jan 2015, 07:19 AM
Hi,

we have problem with the binding, respectively the unbinding of the following viewmodel. If we try to undind the viewmodel we get an exception (undefined is not a function) which comes from the Binder.destroy method. kendo version is: 2013.3.1324

<div class="importantData" data-template="importantDataItem-Template" data-bind="source: getProperties"></div>


this.viewModel = kendo.observable({
                vm: this.ctx.get_viewModel(),
                properties: ["Modified"],
                getProperties: function () {
                    var vm = this.get("vm");
                    var array = [];
 
                    var properties = this.get("properties");
                    var length = properties.length;
                    for (var i = 0; i < length; i++) {
                        array.push(vm.get(properties[i]));
                    }
                    return array;
                }
            });
             
             
            kendo.bind(this.container, this.viewModel);

The other problem is, that the calculated function getProperties is called 4 or 5 times within the binding process.

Thanks in advance!
Michael

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 03 Feb 2015, 08:23 AM
Hello Michael,

I prepared a small demo page based on your code but did not manage to reproduce the error you receive. Could you please check it and let me know what I am missing?
The function is called multiple times because the source is checked multiple times during the binding process. Since it is defined as a function, it gets executed every time the source is checked by the MVVM. In case you define it as a dataSource with transport, the DataSource will be read only once.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Michael
Top achievements
Rank 1
answered on 04 Feb 2015, 10:31 AM
Hello Alexander,

thanks for the answere. I think this problem (on unbind) only occures with an older version (2013), so i will first try to replace it with a newer one. 

Why is it necessery that the MVVM is checking the source 3 or more times?

Thanks in advance!
Michael
0
Alexander Valchev
Telerik team
answered on 06 Feb 2015, 08:45 AM
Hello Michael,

I think this problem (on unbind) only occures with an older version (2013), so i will first try to replace it with a newer one.

Thank you for the follow up. Let me know in case the problem still persists after upgrade.

Why is it necessery that the MVVM is checking the source 3 or more times?

This is a matter of implementation and is connected with the way bindings work. If you wish you may examine the source code:

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
Michael
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Michael
Top achievements
Rank 1
Share this question
or