2

私は基本的なハローワークの例でjsonを取得し、それを自動マッピングしてからobservableにバインドしようとしていますが、基本的な問題が発生していると確信しています。

ajax呼び出しから返されたJSON

"{\"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());

期待していた「helloworld」の代わりに次のものを取得しています

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}
4

1 に答える 1

1

並べ替えると、ko.mappingがオブザーバブルを返すという事実を見落としていたため、それらを関数として呼び出して値を取得する必要があります。

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);
于 2012-09-12T09:21:46.163 に答える