可观察数组的敲除映射插件困难

knockout mapping plugin difficulty with observable array

刚开始使用用于敲除的映射插件。但是在阅读文档后我无法弄清楚为什么我的 observableArray 说它是未定义的。

这里是fiddle。 https://jsfiddle.net/zv39qn64/3/

当我 运行 fiddle 我收到 ReferenceError: Books is not defined.

JS

$(document).ready(function() {
  getModelFromServer()
});


var data = {
  LibraryName: "My home library",
  Books: [
    { Id : 1, Title : "Oliver Twist" },
    {Id: 2,  Title: "Moby Dick"}
  ]
};


function getModelFromServer() {
  $.ajax({
    type: 'GET',
    cache: false,
    data: data,
    url: '/echo/jsonp/',
    success: function(response) {
    var libraryViewModel = ko.mapping.fromJS(response);
    ko.applyBindings(libraryViewModel);
    }
  });
}

HTML

The library <span data-bind="text: LibraryName"></span>
<ul data-bind="foreach: Books">
<li>
    <span data-bind="text: Id"></span> <span data-bind="text: Title"></span>
 </li>
</ul>
function getModelFromServer() {
$.ajax({
    type: 'POST',
    cache: false,
    data: {
        json: JSON.stringify(data)},
    url: '/echo/json/',
    success: function(response) {
    var libraryViewModel = ko.mapping.fromJS(response);
    ko.applyBindings(libraryViewModel);
    }
  });
}

仅将类型更改为 post 和数据条目

https://jsfiddle.net/zv39qn64/4/