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

"Flow Control" bindings in MVVM binding

3 Answers 256 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Stacey
Top achievements
Rank 1
Stacey asked on 02 Jul 2013, 04:03 PM

 

In knockoutJS, I have become accustomed to "Flow Control" bindings for the HTML binding. Such as ...

foreach : http://knockoutjs.com/documentation/foreach-binding.html

<table>
    <thead>
        <tr><th>First name</th><th>Last name</th></tr>
    </thead>
    <tbody data-bind="foreach: people">
        <tr>
            <td data-bind="text: firstName"></td>
            <td data-bind="text: lastName"></td>
        </tr>
    </tbody>
</table>
  
<script type="text/javascript">
    ko.applyBindings({
        people: [
            { firstName: 'Bert', lastName: 'Bertington' },
            { firstName: 'Charles', lastName: 'Charlesforth' },
            { firstName: 'Denise', lastName: 'Dentiste' }
        ]
    });
</script>

and "with" : http://knockoutjs.com/documentation/with-binding.html

<h1 data-bind="text: city"> </h1>
<p data-bind="with: coords">
    Latitude: <span data-bind="text: latitude"> </span>,
    Longitude: <span data-bind="text: longitude"> </span>
</p>
  
<script type="text/javascript">
    ko.applyBindings({
        city: "London",
        coords: {
            latitude:  51.5001524,
            longitude: -0.1262362
        }
    });
</script>


and if : http://knockoutjs.com/documentation/if-binding.html

<label><input type="checkbox" data-bind="checked: displayMessage" /> Display message</label>
  
<div data-bind="if: displayMessage">Here is a message. Astonishing.</div>


and ifnot : http://knockoutjs.com/documentation/if-binding.html

<div data-bind="ifnot: someProperty">...</div>


These have become a vital part of the way I structure views and such, and I would be very upset to lose them. I notice that no such alternatives seem to exist in Kendo UI MVVM? Is this true? Are there any plans for such in the future? This is a very big deal breaker for me.

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 04 Jul 2013, 11:04 AM
Hello Stacey,

Thank you for getting in touch with us. Regarding your questions:
  1. The equivalent of foreach binding in Kendo MVVM is source and template binding. For more information please check the corresponding help article.

  2. It is true that Kendo MVVM does not have a with binding, but you can achieve a similar result by specifying the field path with dot notation syntax.

    <p>
        Latitude: <span data-bind="text: coords.latitude"> </span>,
        Longitude: <span data-bind="text: coords.longitude"> </span>
    </p>
  3. I am afraid that there is no equivalent for if/ifnot bindings. If you would like to see them implemented in the future I suggest you to open a feature request on Kendo UI Feedback portal. In this way the other users would be able to vote for this idea. If it turns out to be popular we will consider it for one of our future releases.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ace
Top achievements
Rank 1
answered on 10 Apr 2015, 03:41 PM

This example does not show how to access a child record. Can you provide an example?

 I need to access Person. Children for a from the Person object.

 

foreach  (child in  Person.Children)

{

console.write(child.firstname);

}

 

0
Petyo
Telerik team
answered on 14 Apr 2015, 07:17 AM
Hello Keith,

If I understand you correctly, you may nest the source/template bindings in case you want to display the child records. If this is not the case, can you please elaborate further? Thank you in advance. 

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
MVVM
Asked by
Stacey
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
ace
Top achievements
Rank 1
Petyo
Telerik team
Share this question
or