Set view attribute functions via code?

3 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    37 posts
    Member since:
    Jul 2012

    Posted 10 Jun 2012 Link to this post

    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. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    2622 posts

    Posted 12 Jun 2012 Link to this post

    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!
  3. Jonathan
    Jonathan avatar
    37 posts
    Member since:
    Jul 2012

    Posted 12 Jun 2012 Link to this post

    Okay. Thanks!
Back to Top