刚从 KnockOut Mapping 开始读取一些 JSON(使用 Google Books API),但似乎无法让它工作。没有错误报告,但没有显示任何内容。可能是我忽略的一个简单问题,但感谢您的评论。
标记....
<body>
<h2>Find Cat in the Hat</h2>
<div>
<input id="booksearch" />
</div>
<div>
<table>
<thead>
<tr>
<th>Volumes</th>
</tr>
</thead>
<tbody data-bind="foreach: model.items">
<tr>
<td data-bind="text: model.id"></td>
</tr>
</tbody>
</table>
</div>
<input id="btnTest" type="button" value="button" />
</body>
<script src="/Scripts/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="/Scripts/knockout-2.2.0.js"></script>
<script src="/Scripts/knockout.mapping-latest.js"></script>
jQuery....
$(document).ready(function () {
//Knockout Test
$('#btnTest').click(function () {
var url = "https://www.googleapis.com/books/v1/volumes?q=the+Cat+In+The+Hat";
var viewModel = {};
$.getJSON(url, function (data) {
viewModel.model = ko.mapping.fromJSON(data);
ko.applyBindings(viewModel);
});
});
});