MVVM support\demo

4 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 23 Mar 2015 Link to this post

    http://demos.telerik.com/kendo-ui/notification/mvvm

    I'm struggling to understand this MVVM demo...a direct query to the object from the model kindof defeats the purpose does it not?  Just being able to initalize the widget with the data-role does not MVVM support make.

    I was assuming I could bind it to a property in the model to show a message(s) or something

    ?
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 25 Mar 2015 Link to this post

    Hi Steve,

    I am not sure I understand your question very well. In case you wish to refer to the widget's instance through some of the viewModel's fields, then you should assign it first. For example:
    <script>
      var viewModel = kendo.observable({
        now: new Date(),
        showMessage: function(){
          this.set("now", new Date());
          var time = kendo.toString(this.get("now"), "HH:mm:ss:fff");
          this.notification.info(time);
        }
      });
      kendo.bind($("#example"), viewModel);
      viewModel.set("notification", $("#ntf1").data("kendoNotification"));
    </script>
    Automatically referencing the widget through the viewModel is not supported out of the box, although it could be achieved using a custom binding.

    If that is not what you are after I would ask you to elaborate a bit.

    Regards,
    Alexander Popov
    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. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 25 Mar 2015 in reply to Alexander Popov Link to this post

    Sorry I was unclear, it's not that I'm wanting to reference the widget in the model...it's that the widget (like others) should be source bindable to an array in the model.

    So I can define that a div in the markup is of type notification, and it's source is defined as X property in my model, then I would just need to add items to my models array where the widget would pop them out (or something).

    The way it currently works is that there isn't a separation of concerns.  The showmessage function is then using jQuery to search the markup to then find the widget and then throw something into its info function...know what I mean?
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 27 Mar 2015 Link to this post

    Thanks for clarifying that Steve.

    The source binding for widgets is a way to set their DataSource when using the MVVM pattern. The Notification widget however is not designed to store all messages that were displayed or are about to be displayed, thus having a DataSource or a source binding support makes little sense. You can achieve similar results by using an observable array and display a message when new item is pushed into it. Here is a proof of concept example.

    Regards,
    Alexander Popov
    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