2

json을 얻고, 자동 매핑하고, 관측 가능으로 바인딩하는 기본적인 hello 작업 예제를 시도하고 있는데, 뭔가 잘못되었다고 확신합니다.Knockout : JSON 문제 매핑/바인딩

JSON은, 나는 내가

function c(){if(0<arguments.length){if(!c.equalityComparer||!c.equalityComparer(d,arguments[0]))c.I(),d=arguments[0],c.H();return this}a.U.La(c);return d} 

답변

1

가 정렬 기다리고 있었다 그 '안녕하세요'대신에 다음 얻고있다

"{\"Content\":\"hello world\"}" 

JS에게 아약스 호출에서

function ViewModel() { 
var self = this; 

self.message = ko.observable(); 

$.getJSON("/home/getmessage", function (response) { 
    var mapped = ko.mapping.fromJSON(response); 
    self.message(mapped.Content); 
}); 
}; 

ko.applyBindings(new ViewModel()); 

을 반환 ko.mapping이 observables를 반환한다는 사실을 간과 했으므로 값을 얻기 위해 observables를 함수로 호출해야합니다.

function viewModel() { 
var self = this; 

self.content = ko.observable(); 

$.getJSON("/home/getmessage", function (response) { 
    var mapped = ko.mapping.fromJSON(response); 
    self.content(mapped.Content()); 
}); 
} 

ko.applyBindings(new viewModel);