相关疑难解决方法(0)

等待ajax结果绑定淘汰赛模型

我有getGeneral调用ajax GET的函数.当ajax收到数据(json)时,它会从给定的json创建KO模型并返回创建的KO.

创建Knockout模型并分配值时,applybindings应调用knockout .这是我的代码:

定义GeneralModel和一些相关的函数(在" GeneralModel.js" 里面):

var GeneralModel = function() {

   //for now it is empty as data ar binded automatically from json
   // CountryName is one of the properties that is returned with json
} 

function getGeneral(pid) {
    $.ajax({
        url: "/api/general",
        contentType: "text/json",
        dataType: "json",
        type: "GET",
        data: { id: pid},
        success: function (item) {
            var p = new GeneralModel();
            p = ko.mapping.fromJS(item);
            return p;
        },
        error: function (data) {

        } …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery json knockout.js

1
推荐指数
1
解决办法
4353
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

json ×1

knockout.js ×1