我有一个 JSON 数据。我将其转换为 ko.observableArray。我的意图是将它绑定到我的视图。
JSON如下:
{ "1" : { "asr" : "15:50", "fajr" : "03:00", "isha" : "21:31", "maghrib" : "19:02", "zuhr" : "12:21" },
"2" : { "asr" : "15:51", "fajr" : "02:55", "isha" : "21:35", "maghrib" : "19:04", "zuhr" : "12:21" },
"3" : { "asr" : "15:53", "fajr" : "02:51", "isha" : "21:39", "maghrib" : "19:07", "zuhr" : "12:21" },
"4" : { "asr" : "15:54", "fajr" : "02:46", "isha" : "21:42", "maghrib" : "19:09", "zuhr" : "12:20" }
}
这是将 JSON 转换为 observableArray 的 javascript:
self.prayerData(jQuery.parseJSON(data));
$.each(self.prayerData(), function (days) {
// It works and displays the data
console.log(days + " - " + this.fajr + " | " + this.asr);
});
这是我为绑定数据所做的,但它不起作用:
<!-- ko foreach:prayerData()-->
<tr>
<td data-bind="text: index"></td> <!-- Display the current row -->
<td data-bind="text: fajr"></td>
<td data-bind="text: zuhr"></td>
<td data-bind="text: asr"></td>
<td data-bind="text: maghrib"></td>
<td data-bind="text: isha"></td>
</tr>
<!-- /ko -->
在淘汰赛中绑定此类数据的任何帮助。