Closed Yigmoryar closed 5 years ago
var model = { movies:[ { id:256889, name:"item Name", description:"Description of Item", showtimes:[ {start:"11:45am", duration:"120 minutes", soldOut:false, pricingType:"Matinee"}, {start:"6:45pm", duration:"120 minutes", soldOut:false, pricingType:"Evening"} ] } ] }; var options = { arrayChildId:{//child item id "{root}.movies":"id" }, extend:{ "{root}.movies[i]":"ExtendWithSelectable",//Reference shared function by name "{root}.movies[i].showtimes[i]": function(showtime){ //Reference shared function directly options.shared.ExtendWithSelectable(showtime); showtime.price = ko.computed(function(){ if(showtime.pricingType = "Matinee"){ return 6.75; } else if(showtime.pricingType = "Evening"){ return 10.25; } }); } }, shared:{ ExtendWithSelectable:function (item){ item.selected = ko.observable(false); return item; } } } var viewmodel = ko.viewmodel.fromModel(model, options);
pricingType
// showtime.price = ko.computed(function(){ // if(showtime.pricingType = "Matinee"){ // return 6.75; // } // else if(showtime.pricingType = "Evening"){ // return 10.25; // } // });
so, is this a bug? I'll appreciate if anyone could tell me what happened, thanks.
You made a basic Javascript error, this is not: if(showtime.pricingType = "Matinee") but if(showtime.pricingType == "Matinee") and so on.
if(showtime.pricingType = "Matinee")
if(showtime.pricingType == "Matinee")
thx. I'm so ashamed.
pricingType
would not be observable.pricingType
would be observable.so, is this a bug? I'll appreciate if anyone could tell me what happened, thanks.