knockout.js를 사용하여 정렬 된 목록을 작성 중입니다. 간단한 관측 가능한 배열로 작업하는 버전이 있지만 어떻게 json 데이터로 작업하고 매핑 플러그인을 사용할 수 있습니까?knockout.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());
여전히지도 플러그인을 사용하여 json의 데이터를 매핑하고 싶습니다. – simple
@imple이 더 많은 explantations로 업데이트되었습니다. –