Reputation: 351
I have function like
function Configuration(data) {
var self = this;
self.configKey = data.pKey;
self.configName = data.configName;
self.configNumber = data.modelnumber;
self.configMTP = ko.observable(data.mTP);
self.configMDP = ko.observable(data.mDP);
}
And my view model like
function AppViewModel() {
var self = this;
self.Configurations = ko.observableArray([]);
self.selConfig = ko.observable();
}
And binding is like below
<select data-bind="options:categories,optionsCaption:'All',value:selCatgy ">
</select>
The Configurations array in the viewmodel has the list of configuration objects. When user selects particular configuration the selected 'selConfig' property is getting updated with selected configuration object.. Now if i want to bind the other properties(like configMTP,configMDP) in the screen from 'selConfig', is it possible to do?
I did something like below. Is there any other way we can achieve the same?
<!-- ko foreach:selConfig-->
<pre data-bind="text: configMTP"></pre>
<input data-bind="value: configMDP" />
<input data-bind="value: configName" />
<!-- /ko -->
Thanks,
Praveen.
Upvotes: 0
Views: 72
Reputation: 139798
If you want to bind to one objects properties you need to use the with
binding instead of the foreach
:
<!-- ko with: selConfig -->
<pre data-bind="text: configMTP"></pre>
<input data-bind="value: configMDP" />
<input data-bind="value: configName" />
<!-- /ko -->
Upvotes: 1