treeview drop on backbone page cant reference view from drop handler

3 posts, 1 answers
  1. Manuel Hernandez
    Manuel Hernandez avatar
    3 posts
    Member since:
    Sep 2013

    Posted 10 Apr 2014 Link to this post

    I'm using treeview from Backbone using Marionette.

    I initialize  the treeview when I call the view render method.

    View.myPanel = Marionette.ItemView.extend(
    {
          render: function () {
                this.treeview = this.$el.find("#treeview").kendoTreeView({
                dataSource: this.hierarchicalDataSource,
                      dataTextField: ["item"],
                      dragAndDrop: true,
                      loadOnDemand: false,
                     drop: this.onDrop
                }).data("kendoTreeView"),
                 this.treeview.expand(".k-item");
        },
               
          onDrop: function (e) {
                ...
                code to create model goes here ......
               ... 
                this.saveItem(localModel, false);
       }

    The problem I have is that when I try and call this.saveItem, I have no reference to this. which normally would be the view itself. Instead "this" refers to the treeview object itself. I tried to extend the trreview with BackBone.Events but that causes me to lose the drag and drop functionality, I also tried passing the view object as a parameter to  the drop handler but that replaces the event parameter in the onDrop function.

    Any help would be appreciated, thanks! 


  2. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 14 Apr 2014 Link to this post

    Hello Manuel,

    Instead of providing the handler with

        drop: this.onDrop

    you should save the function context, for example via $.proxy

        drop: $.proxy(this.onDrop, this)

    Regards,
    Alex Gyoshev
    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. Manuel Hernandez
    Manuel Hernandez avatar
    3 posts
    Member since:
    Sep 2013

    Posted 08 Aug 2014 in reply to Alex Gyoshev Link to this post

    Sorry for the delay in responding but this worked. Awesome thanks!
Back to Top