Do I really have to use get() in templates?

2 posts, 0 answers
  1. Sergei
    Sergei avatar
    44 posts
    Member since:
    Aug 2012

    Posted 14 Mar 2014 Link to this post

    It seems to be working both ways but the documentation says to use get() on observable objects. I prefer the conciseness of the first example with direct invocations.  What dangers am I putting myself in by not using get()?


    <div data-template="trade-purchase-listing-template1b" data-bind="source: this">
        <script id="trade-purchase-listing-template1b" type="text/x-kendo-template">
            #if (data.current_trade_balance !== null && data.listing.price) {#
                #if (data.current_trade_balance >= data.listing.price) {#

    ..vs..

    <div data-template="trade-purchase-listing-template1b" data-bind="source: this">
        <script id="trade-purchase-listing-template1b" type="text/x-kendo-template">
            #if (data.get('current_trade_balance') !== null && data.get('listing.price')) {#
                #if (data.get('current_trade_balance') >= data.get('listing.price')) {#

    Here's how data is initialized: 

    model.data = kendo.observable({
        listing: {},
        current_trade_balance: null,
        ....
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 18 Mar 2014 Link to this post

    Hi Sergei,

    The get method is used mainly when you want to create dependent ViewModel methods. In your particular case there is no need to use the get method inside the template.
    Please feel free to use direct invocations if this syntax is more convenient for you.

    Regards,
    Alexander Valchev
    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
Back to Top