I am using Breeze which automatically creates a nested Observablearray structure consisting of dependent observables at different levels.
I have tried to emulate the structure in this fiddle. Simply put I have a client entity being returned from the server with a related user entity which Breeze is automatically mapping to an observable array. I just need to display some client properties and some user properties on my form from this array.
HTML
<div>
<select data-bind="options: clientAndStaff, optionsText: 'clientId', value: 'clientId', optionsCaption: 'Select a client'"></select>
</div>
VM
var esp= esp||{};
esp.ClientDetails = function(x){
this.clientId = new ko.dependentObservable(function(){return x.clientId;});
this.User = new ko.dependentObservable(function(){return x.ClientStaffDetails;});
};
esp.ClientStaffDetails = function(x){
var FirstName = new ko.dependentObservable(function(){return x.firstName;});
var LastName = new ko.dependentObservable(function(){return x.lastName;});
};
esp.vm = new (function()
{
this.clientAndStaff= ko.observableArray(
[
new esp.ClientDetails({clientId:1
,clientStaff:new esp.ClientStaffDetails({firstName:'first',lastName:'example'})
}),
new esp.ClientDetails({clientId:2
,clientStaff:new esp.ClientStaffDetails({firstName:'second',lastName:'example'})
})
]
);
});
ko.applyBindings(esp.vm);
Fiddle
Can anyone tell me how to bind the optionsText to the firstName or better still firstName + LastName given the observableArray structure. Thanks in advance