Set the whole city object as value for selectedCity
. You can also add a computed observable for retrieving text.
function ViewModel() {
var self = this;
self.Cities = ko.observableArray([]);
self.selectedCity = ko.observable();
self.selectCity = function (city) {
self.selectedCity(city);
};
self.selectedCityNameRu = ko.pureComputed(function () {
var selectedCity = self.selectedCity();
return selectedCity ? selectedCity.CityNameRu : '';
}, self);
Then in your html bind to selectedCityNameRu
<span data-bind="text: selectedCityNameRu"></span>
No comments:
Post a Comment