简体   繁体   English

AJAX调用返回动态列表…正在加载到ko.observableArray

[英]AJAX call returning a dynamic list … loading to ko.observableArray

I am trying to call to a Web service which returns a dynamic list. 我试图调用返回动态列表的Web服务。 I need the list in JSON and I need to then load it to a ko.observableArray . 我需要JSON中的列表,然后将其加载到ko.observableArray I know the call to the Web service works, but I keep getting errors on the load. 我知道对Web服务的调用是可行的,但我在加载过程中一直遇到错误。 Is my syntax okay? 我的语法可以吗?

function getEm(zip) {
    $.ajax('/Services/TheatreLocationList.asmx/getTheatres', {
        type        : 'POST',
        contentType : 'application/json; charset=utf-8',
        dataType    : 'json'
    }).done(function(data) {
        self.theatreData = ko.observableArray(data || [ ]);
    });
}

Try setting the value of data before passing the argument. 传递参数之前,尝试设置数据值。 I would console.log(json) to make sure you're getting back what you expect from your service call. 我会用console.log(json)来确保您能从服务呼叫中得到期望的结果。

function getEm(zip) {
    $.ajax('/Services/TheatreLocationList.asmx/getTheatres', {
        type        : 'POST',
        contentType : 'application/json; charset=utf-8',
        dataType    : 'json'
    }).done(function(json) {
        var data = json.length > 0 ? json : [];
        self.theatreData = ko.observableArray(data);
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM