Computed value based on another computed value?

4 posts, 0 answers
  1. axwack
    axwack avatar
    37 posts
    Member since:
    Aug 2012

    Posted 16 Jul 2012 Link to this post

    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?
  2. Dennis
    Dennis avatar
    1 posts
    Member since:
    Jun 2008

    Posted 16 Jul 2012 Link to this post

    I think you need to call:

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

    because this.BondProceeds() calls get().

    I hope this helps.
  3. Kendo UI is VS 2017 Ready
  4. kashyapa
    kashyapa avatar
    7 posts
    Member since:
    Jan 2011

    Posted 20 Jul 2012 Link to this post

    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
  5. axwack
    axwack avatar
    37 posts
    Member since:
    Aug 2012

    Posted 12 Aug 2012 Link to this post

    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() #>

Back to Top
Kendo UI is VS 2017 Ready