My input parameter for the code below is just a tablename,
I was able to query the data return in json format, however, i am not able to display my rows item of data. any idea what did i do wrong?
<script>
var invtype = "@ViewBag.invtype";
function ViewModel() {
var self = this;
function ColName(tbstruct){
this.ColumnName = tbstruct.ColumnName
}
self.TBStruct = ko.observableArray();
self.items = ko.observableArray();
self.invtype = invtype;
self.Load = function () {
//expected data for self.items
//[{"$id":"1","Id":2,"Inv_Id":"PV0001-1","ACX_No":"6","ACX_Name":"ABC","S_No":"5", "Acc_Class":"Local","Direction":"Two-Way"},{"$id":"2","Id":2,"Inv_Id":"PV0002-1","ACX_No":"3","ACX_Name":"CKD","S_No":"6", "Acc_Class":"Local","Direction":"Two-Way"}]
$.ajax({
url: "@Url.Content("~/api/")"+self.invtype,
type: 'GET',
dataType: 'JSON',
success: function (data) {
// Map the returned JSON to the View Model
self.items = data;
}
});
//expected data
//[{"$id":"1","ColumnName":"Id","system_type_id":56,"primaryCol":1}, {"$id":"2","ColumnName":"Inv_Id","system_type_id":231,"primaryCol":0},{"$id":"3","ColumnName":"ACX_No","system_type_id":175,"primaryCol":0},{"$id":"4","ColumnName":"ACX_Name","system_type_id":175,"primaryCol":0},{"$id":"5","ColumnName":"S_No","system_type_id":175,"primaryCol":0} {"$id":"27","ColumnName":"Acc_Class","system_type_id":231,"primaryCol":0},{"$id":"28","ColumnName":"Direction","system_type_id":231,"primaryCol":0} ]
$.ajax({
url: "@Url.Content("~/api/inventories/")"+self.invtype,
type: 'GET',
dataType: 'JSON',
success: function (data) {
// Map the returned JSON to the View Model
$.each(data,function(i,dt){
//console.log(dt.ColumnName);
self.TBStruct.push(new ColName(dt));
});
//console.dir(self.TBStruct);
}
});
return self;
};
}
var View = new ViewModel();
ko.applyBindings(View.Load());
here i am trying to display them out.
<thead>
<tr data-bind="foreach: TBStruct">
<th data-bind="text: ColumnName"></th>
</tr>
</thead>
<tbody >
<tr data-bind="foreach: items" >
<td data-bind="text:$data"></td>
</tr>
</tbody>
</table>