I was reading other answers but I can't find the solution, the error says: Error: Unable to parse bindings. Message: ReferenceError: AdvertisementLegs is not defined; Bindings value: foreach: AdvertisementLegs, and I cant find why, becouse its defined in the model:
Here is the models
Main Model.js
self.selectedAd = ko.observable();
self.selectAd = function (item, data) {
self.selectedAd = ko.observable(new AdvertisementMgr());
self.advertisementManager().getAdvertisementById(item);
$('#windowEditAd').jqxWindow('open');
};
Advertisement Model.js
var self = this;
//URLS
self.CompanyName = ko.observable("");
//Lists
self.AdvertisementLegs = ko.observableArray();
self.getAdvertisementById = function (dataItem) {
$.ajax({
cache: false,
url: mViewModel.apiUrl + 'Advertisement',
type: "GET",
contentType: "json",
dataType: "json",
data: {
adId : dataItem.AdvertisementId()
},
success: function (data) {
mViewModel.selectedAd(data);
},
error: function (xhr, status, error) {
alert(error.message);
}
});
};
the json response is:
CompanyName
"Flotsum Strategies, Inc"
AdvertisementLegs
[Object { AdvertisementLegId=6, Action="BUYER", Volume=1, más...}]
0
Object { AdvertisementLegId=6, Action="BUYER", Volume=1, más...}
AdvertisementLegId
6
Action
"BUYER"
Price
0
AdvertisementId
4
AdvertisementLegType
"TL"
The view is:
<div data-bind="with: $root.selectedAd">
<span data-bind="text: CompanyName"></span>
<input data-bind="value: CompanyName" type="text" class="txt4 leg_data_vol1" style="width: 50px; text-align: center;" id="leg_data_vol1" />
<table border="0" cellspacing="0" cellpadding="0" class="volaxe-table">
<tbody data-bind="foreach: AdvertisementLegs ">
<tr >
<td>
lalla
<input data-bind="value: Volume" type="text" class="txt4 leg_data_vol1" style="width: 50px; text-align: center;" id="leg_data_vol1" />
</td>
</tr>
</tbody>
</table>
</div>
CompanyName has no problem the issue is with the array it says Message: ReferenceError: AdvertisementLegs is not defined. Why it says that it cant bind it if its in the model and it has results?