loading a knockout.js observableArray() from .ajax() call

后端 未结 5 1186
半阙折子戏
半阙折子戏 2021-02-01 20:10

This puzzles me. It must be something small I\'m not seeing. I\'m trying to load a very simple observableArray in knockout with an ajax call.

javasc

5条回答
  •  悲哀的现实
    2021-02-01 20:20

    var self=this;
    //var self first line in model
    
    $.ajax({
                url: ",
                dataType: "json",
                contentType: 'application/json',
                type: "POST",
                data: JSON.stringify({ }),
                processdata: true,
    
                beforeSend: function () {
                    $.mobile.loading('show');
                },
    
                error: function (xhr, textStatus, errorThrown) {
                    alert('Sorry!');
                },
    
                success: function (data) {
    
                    $.mobile.loading('hide');
                    if (data.result!= '') {
                        self.vendors(data.result);
    
    
    
                    } else {
                        self.vendors({something});
    
                    }
                }
            });
    

    Use self.vendors not this viewModel.vendors

提交回复
热议问题