Hi guys i have a strange problem with KO Observable array and my UI ,if i pass a fixed model to my observable array this one works ! and show the select options correctly but if make this one dynamically simply not show anything, i already made a first one select option to be dynamically working and it works perfect!, but the second option simply does not work.
Here are the code of my model for the options
var TipoModel = function(data) {
var self = this;
self.id = ko.observable(data.id);
self.name = ko.observable(data.name);
};
var HabitacionModel = function(Huespedes) {
...
self.loadRoomsType = function() {
ajax("/api/foro/loadrooms", {}, function(data) {
self.tipoHabitacion = ko.observableArray([]);
$.each(data, function(index, habitacion) {
var hab = new TipoModel({
id: habitacion.id,
name: habitacion.nombreHabitacion
});
self.tipoHabitacion.push(hab);
});
}, "GET");
console.log(self.tipoHabitacion());
}
self.loadpartnersType = function() {
ajax("/api/foro/loadpartners", {}, function(data) {
var self = this;
self.tipoHuesped = ko.observableArray([]);
$.each(data, function(index, socio) {
var x = new TipoModel({
id: socio.id,
name: socio.nombre
});
self.tipoHuesped.push(x);
});
console.log(self.tipoHuesped());
}, "GET");
}
the load rooms work but the parters function is not working and is the same code only a few changes but its the same .
<select style="width:30%; height:100%; margin-top:4px; background-color:transparent; border-color:#729A2B;" data-bind="options: tipoHuesped,
value: selectedHuesped,
optionsText: 'name',
optionsValue: 'id',
optionsCaption: 'Escoge...'" required></select>
if i define like this the observable array from the start it works
self.tipoHuesped = ko.observableArray([
new TipoModel({
id: "1",
name: "Aeroméxico"
}),
new TipoModel({
id: "2",
name: "Magnicharters"
})
]);
i want to make this dynamically cause more data will be added soon, hope u can help me guys. Thanks