get selected option text in knockout

后端 未结 3 1792
情歌与酒
情歌与酒 2020-12-19 02:50

I am using knockoutjs to bind a select list. Here is a Sample , I want to get selected option text instead of selected value.

How to get it using knockoutjs ?

<
3条回答
  •  死守一世寂寞
    2020-12-19 03:47

    vm.selectedCountryName = ko.computed(function () {
            var text = '';
            ko.utils.arrayForEach(vm.countries(), function (item) {
                if (item.CountryId == vm.selectedCountry()) {
                    text = item.CountryName;
                    return;
                }
            });
            return text;
        });
    

提交回复
热议问题