undefined is not a function on unbinding a viewmodel

4 posts, 0 answers
  1. Michael
    Michael avatar
    8 posts
    Member since:
    Feb 2013

    Posted 30 Jan 2015 Link to this post

    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
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 03 Feb 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Michael
    Michael avatar
    8 posts
    Member since:
    Feb 2013

    Posted 04 Feb 2015 in reply to Alexander Valchev Link to this post

    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
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 06 Feb 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready