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

MVVM support\demo

3 Answers 106 Views
Notification
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 23 Mar 2015, 07:03 PM
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

?

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 25 Mar 2015, 02:35 PM
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!
 
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 25 Mar 2015, 02:40 PM
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?
0
Alexander Popov
Telerik team
answered on 27 Mar 2015, 08:50 AM
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!
 
Tags
Notification
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Alexander Popov
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Share this question
or