Split the data binding of KnockoutJS into table C#
This is my previous topic about getting the value which is displayed as JSON and parse them into table rows and columns, the answer could solve my question thanks to @GoTo however, because I have to split the structure of KnockOut JS into js files, therefore create another question for me
I have splitted them into 3 files, 2 js files and one cshtml file which contains the table
The first js is :
biz.js
var mapDictionaryToArray =
function (dictionary) {
var result = [];
for (var key in dictionary) {
if (dictionary.hasOwnProperty(key)) {
result.push({
key: key,
value: dictionary[key]
});
}
}
return result;
};
The second js is :
config.js
function ConfigViewModel() {
self.testParams = mapDictionaryToArray;
self.contents = ko.observable({
"reference": "2Z94",
"car_id": "9861"
});
}
$(document).ready(function () {
ko.applyBindings(new ConfigViewModel());
});
The cshtml file :
HTML cshtml :
<table class="table table-hover">
table test:
<tbody data-bind="foreach: testParams(contents())">
<tr class="data-hover">
<td>
<span id="textKey" data-bind="text: key"></span>
</td>
<td>
<span id="textValue" data-bind="text: value"></span>
</td>
</tr>
</tbody>
</table>
The result from fiddler in my previous topic worked great (FiddlerKnockout), but then it doesn't work for the split of new structure