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

Set view attribute functions via code?

2 Answers 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 11 Jun 2012, 12:45 AM
Is there a way to do something like: http://jsfiddle.net/sK6Wy/15/ 

I want to do this because I define all my functions in modules in RequireJS. If I cannot do this, then I will I have to expose them to the window (which can cause pollution).

2 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 12 Jun 2012, 02:51 PM
Hi Jonathan,

To achieve that I would suggest two approaches:
  1. Recommended: You can encapsulate the functions and bind them through the data attribute in the following way: 
    <div data-role="view" data-layout="default" data-title="Foo" id="foo" data-show="foo.show"></div>
    // ....
    var foo = (function() {
      return {
        show: function() {
           console.log("bar")          
        }
      }
    })();

To illustrate such approach in action, I updated your jsFiddle example.

  2.  Not Recommended: it is possible to hook up to the events with the bind() method in the $(document).ready. Please note in this case only the first view is initialized due to performance reasons. In other words, this approach will allow you to bind the events only for the first view. 
$(document).ready(function() {
    $("#foo").data("kendoMobileView").bind("init", function() {
        //....
    });
});

In addition, if you got confused by the mobile application events - at present those events are not exposed. I apologize for the inconvenience - the problem was addressed and our documentation is updated.

I hope this helps.

Greetings,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jonathan
Top achievements
Rank 1
answered on 12 Jun 2012, 09:39 PM
Okay. Thanks!
Tags
General Discussions
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or