How to display No Data when observable array is empty?

后端 未结 2 1175
庸人自扰
庸人自扰 2021-01-18 00:21

I\'m new to Knockout.js and I\'m trying to display data from observable array to a table. The problem I have is it generates two tbody tags. But if

2条回答
  •  青春惊慌失措
    2021-01-18 00:55

    Actually, your html markup is fine. I added the following javascript to your markup

    $(document).ready(function() {
        var a = [{
            permit: "permit1",
            region: 'region1',
            landowner: 'landowner'},
        {
            permit: "permit2",
            region: 'region2',
            landowner: 'landowner2'}];
        var vm = {};
        vm.requestList = ko.observableArray([]);
    
        ko.applyBindings(vm);
    
        $('#loadData').click(function() {
            var a1 = ko.mapping.fromJS(a);
            var b1 = a1();
            vm.requestList(b1);
        });
    });​
    

    And it seems to be working as you describe how you want things to work. It is working at http://jsfiddle.net/photo_tom/xmk3P/10/

提交回复
热议问题