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

treeview drop on backbone page cant reference view from drop handler

2 Answers 61 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Manuel Hernandez
Top achievements
Rank 1
Manuel Hernandez asked on 10 Apr 2014, 04:45 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 14 Apr 2014, 02:05 PM
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!
 
0
Manuel Hernandez
Top achievements
Rank 1
answered on 08 Aug 2014, 09:26 PM
Sorry for the delay in responding but this worked. Awesome thanks!
Tags
TreeView
Asked by
Manuel Hernandez
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Manuel Hernandez
Top achievements
Rank 1
Share this question
or