0

foreachでデータを表示するWebアプリケーションでノックアウトを使用しています(必要なすべてのライブラリが含まれています)

そして、私は次のエラーを受け取ります:

Error: Unable to parse bindings. Message: ReferenceError: d is not defined; Bindings value: foreach: d
[Break On This Error]   

...+c+" } ";return new Function("sc",c)},kb:function(a,b){if(b.compareDocumentPosit...

私のJSON:

{"d":[{"__type":"listingItem:#applicationModel","award_text":"","channel_id":5,"constructed_short_descriptionen":"","constructed_short_descriptiongr":"","constructed_titleen":"","constructed_titlegr":"","country_id"...

私のコード:

var Listing_ViewModel = {};

    var data = $.getJSON("listings.svc/Listing_Get_Items?",
                {
                    startdate: "2012-09-21 00:00:00",
                    stopdate: "2012-09-22 00:00:00",
                    channel_id: "5"
                }, function (data) {
                    // Now use this data to update your view models, 
                    // and Knockout will update your UI automatically 
                    //var parsed = JSON.parse(data);
                    alert(data.d[0].duration);
                    Listing_ViewModel = ko.mapping.fromJSON(data);
                    //alert(ko.mapping.toJS(Listing_ViewModel));
                    ko.applyBindings(Listing_ViewModel);
                    //        ko.applyBindings({
                    //          
                    //        });
                })

HTMLコード:

<!-- ko foreach: d -->
    <li class="item item-even" id="id_1" title="1">
    </li>
<!-- /ko -->

私が間違っていることは何ですか?すみません、私は完全に緑です!

4

1 に答える 1

3

fromJSON問題は、あなたが本当に意味するときに使用している可能性が最も高いですfromJS。JSON文字列の読み取り中に、$.getJSONすでにオブジェクトが作成されます。Javascriptオブジェクトを読み込みます。ko.mapping.fromJSONko.mapping.fromJS

詳細については、このJSFiddleを参照してください:http://jsfiddle.net/hB3Rm/

基本的に、次の行を変更します。

Listing_ViewModel = ko.mapping.fromJSON(data);

この行に:

Listing_ViewModel = ko.mapping.fromJS(data);
于 2012-09-25T01:24:47.880 に答える