How can I change select component's value from JS(TS) with using Knockout?

27 views
Skip to first unread message

Tuğrul Emre Atalay

unread,
Jun 24, 2015, 10:38:03 AM6/24/15
to knock...@googlegroups.com

I have 2 select component and they should effect each other. I've tried to solve this problem with manual but I've been astonished.

Note 1: selectedIndex didn't work.

Note 2: changing value at JS(TS) didn't update component.

Here is HTML codes:

 <div>
        <div class="summary-row-item-table bottomBorder">
            <div class="summary-row-item-label">
                {{GetString('InstallmentRangeMonth')}}
            </div>
            <select data-bind="options: interestRates, optionsText: 'TaksitAraligi', value: selectedInstallmentRange"></select>
        </div>
        <div class="summary-row-item-table bottomBorder">
            <div class="summary-row-item-label">
                {{GetString('TransferAmountTL')}}
            </div>
            <select data-bind="options: interestRates, optionsText: 'TutarAraligi', value: selectedAmountRange"></select>
        </div>
        <div class="summary-row-item-table bottomBorder">
            <div class="summary-row-item-label">
                {{GetString('InterestRate')}}
            </div>
            <div class="summary-row-item-value">
                % {{interestRates()[selectedRate()].FaizOrani}}
            </div>
        </div>
        <div class="summary-row-item-table bottomBorder">
            <div class="summary-row-item-label">
                {{GetString('TransactionFeeExceptBSMV')}}
            </div>
            <div class="summary-row-item-value">
                {{interestRates()[selectedRate()].IslemUcretiBilgisi}}
            </div>
        </div>
    </div>

Here is TypeScript Codes

this.interestRates().push({IslemUcretiBilgisi : 'lale',FaizOrani:'lale2',TutarAraligi:'lale3',TaksitAraligi:'lale4'});
this.interestRates().push({IslemUcretiBilgisi : 'example1',FaizOrani:'example2',TutarAraligi:'example3',TaksitAraligi:'example4'})

    var _self = this;
    this.selectedRate = ko.computed(function () {
        var tempNumIns = 0; var tempNumAmo = 0;
        if (_self.selectedInstallmentRange())
            _self.interestRates().forEach(function (item: any, i: number = 0) {
                if (item.TaksitAraligi === _self.selectedInstallmentRange().TaksitAraligi) {
                    tempNumIns = i;
                }
                i++;
            });
        if (_self.selectedAmountRange())
            _self.interestRates().forEach(function (item: any, i: number = 0) {
                if (item.TutarAraligi === _self.selectedAmountRange().TutarAraligi) {
                    tempNumAmo = i;
                }
                i++;
            });
        _self.lastIndex = (tempNumAmo == _self.lastIndex ? tempNumIns : tempNumAmo);
        _self.selectedInstallmentRange(_self.interestRates()[_self.lastIndex].TutarAraligi);
        _self.selectedAmountRange(_self.interestRates()[_self.lastIndex].TaksitAraligi);
        return _self.lastIndex;
    }, this);

If there is a way to use selectedIndex, it will be so easy and nice coded.

If you want my +1 on SOF, go :)
Reply all
Reply to author
Forward
0 new messages