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

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

1 Answer 64 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Sergei
Top achievements
Rank 1
Sergei asked on 14 Mar 2014, 07:15 PM
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,
    ....

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 Mar 2014, 08:52 AM
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!
 
Tags
MVVM
Asked by
Sergei
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or