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

Binding ListView items with MVVM and dataBound event

4 Answers 446 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jaap
Top achievements
Rank 2
Jaap asked on 03 Sep 2012, 02:30 PM
Hello,



I use MVVM to bind a ListView to my viewmodel and also the item template uses the MVVM pattern. The ListView dataBound event is binded to a function on my viewmodel.

The problem is that, when my dataBound function is called, the items exists, but are not yet binded to the data.

It appears that the item binding is triggered in the ListView.refresh function by calling the trigger('dataBound') function. There are actually 2 dataBound events, my event and an event of the binding system. And it appears my event is called first.

In my opinion it should be ensured that the binding event is always the first one executing.



I can workaround it by attaching my dataBound event after the binding of the ListView ( with listview.bind('dataBound', function (e) {...}) ), but that is against the MVVM pattern.



Regards, Jaap

4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 06 Sep 2012, 10:48 AM
Hello Jaap,

We tried reproducing the behavior you described in the following jsBin, to no avail. If this is not your scenario, please elaborate by modifying the example and showing the issue at hand.

Regards,

Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jaap
Top achievements
Rank 2
answered on 06 Sep 2012, 11:07 AM
The template must use MVVM style binding.

Change the h3 tag to this: <h3 data-bind="text:ProductName"></h3>

Then you will see that the console.log writes a 'undefined'.



Regards, Jaap
0
Alex Gyoshev
Telerik team
answered on 10 Sep 2012, 08:52 AM
Hello Jaap,

Using the template output (rather than binding the text through MVVM is much faster, so this would only make sense for computed values. This is not supported at the present time. Feel free to open a feature request on uservoice.

Kind regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jaap
Top achievements
Rank 2
answered on 10 Sep 2012, 09:06 AM
Ok, speed is a valid reason.

Currently I use in ASP.NET MVC the DisplayTemplates (per property type) for my controls in regular pages and I wanted to reuse them also for my templates.

Looks like I need to create 2 versions of my display template, one for using with databinding and one for templating.

Perhaps I can use one template with some switch in it.



Regards, Jaap
Tags
MVVM
Asked by
Jaap
Top achievements
Rank 2
Answers by
Alex Gyoshev
Telerik team
Jaap
Top achievements
Rank 2
Share this question
or