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

Computed value based on another computed value?

3 Answers 194 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
axwack
Top achievements
Rank 1
axwack asked on 16 Jul 2012, 07:07 PM
With telerik MVVM is this possible? I have a one field that is calculated fine :

BondProceeds: function(){                                       
                                        return this.get("UnderlyingPar") * (this.get("UnderlyingPrice")/100);
                                       },

I then want another attribute that is computed dependent upon this:

TotalAmount: function(){
                                       return this.get("BondProceeds") - this.get("FloaterAmount");
                                        }

I don't get anything in the textbox for Total Amount. Is this possible?

3 Answers, 1 is accepted

Sort by
0
Dennis
Top achievements
Rank 1
answered on 17 Jul 2012, 01:24 AM
I think you need to call:

this.BondProceeds() - this.get("FloaterAmount")

because this.BondProceeds() calls get().

I hope this helps.
0
kashyapa
Top achievements
Rank 1
answered on 20 Jul 2012, 05:55 PM
here is the code:

<div id="container">
        <label>Underlying Par: <input data-bind="value: underlyingPar" /></label>
        <br />
        <label>Underlying Price: <input data-bind="value: underlyingPrice" /></label>
        <br />
        <label>Floater Price: <input data-bind="value: floaterPrice" /></label>
        <br />
        <label>Bind Proceeds: <span data-bind="text: BondProceeds" /></label>
        <br />
        <label>Total Amount:<span data-bind="text: TotalAmount" ></span></label>
        <script>
            $(document).ready(function () {


                var viewModel = kendo.observable({
                    underlyingPar: 100,
                    underlyingPrice: 100,
                    floaterPrice: 100,
                    BondProceeds: function () {
                        return this.get("underlyingPar") * (this.get("underlyingPrice") / 100)
                    },
                    TotalAmount: function () {
                        return this.BondProceeds() - this.get("floaterPrice")
                    }


                });


                kendo.bind($("#container"), viewModel)
            });
        </script>
    </div>

regards
Lohith
Tech Evangelist
Telerik India
0
axwack
Top achievements
Rank 1
answered on 12 Aug 2012, 02:29 PM
Thank you for your reply.

On this same thread, if I require the computation in a grid using a template do I do someting in my template like
<#=this.BondProceeds() #>

Tags
MVVM
Asked by
axwack
Top achievements
Rank 1
Answers by
Dennis
Top achievements
Rank 1
kashyapa
Top achievements
Rank 1
axwack
Top achievements
Rank 1
Share this question
or