ノックアウト js を使用して並べ替えられたリストを作成しています。単純な観測可能な配列で動作するバージョンがありますが、json データとマッピング プラグインを使用して動作させるにはどうすればよいですか?
http://jsfiddle.net/infatti/x66Ts/
// Here is my json data
var viewModel;
$.getJSON('http://echo.jsontest.com/name/Stuart', function (data) {
viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
});
// Here is my working version of the simple observable array. How can it work using json data and the mapping plugin?
var ListSortModel = function () {
// my items
this.allItems = ko.observableArray([
{ name: 'Denise' },
{ name: 'Charles' },
{ name: 'Bert' }
]);
// sorter
this.sortItems = function() {
this.allItems(this.allItems().sort(function(a, b) { return a.name > b.name;}));
};
};
ko.applyBindings(new ListSortModel());