3
我有一個JSON數據。我將它轉換爲ko.observableArray。我的意圖是將其綁定到我的視圖。Binding multidimensional knockoutjs 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 -->
任何幫助綁定這種數據在挖空。
謝謝@RPNiemeyer,它的工作原理 – Maxali 2012-04-06 00:33:30