第一次单击按钮时,它不会将数据绑定到表中

For the first time button click it is not binding data into table,

本文关键字:数据绑定 按钮 单击 第一次      更新时间:2023-09-26

第一次单击按钮时,它不会将数据绑定到表中,第二次单击后它再次被绑定。我需要绑定数据以进行首次点击

var resturant=angular.module('resturantmodule',[]);
resturant.controller('resturantcontroller',function($scope,$http){
    $scope.resturants=[];
    $scope.onResturantClick=function(){
        var url="https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20local.search%20where%20zip='"+$scope.pin +"'and%20query='"+$scope.order +"'&format=json&diagnostics=false&callback=";
        $http.get(url).success(function(data){
        $scope.resturants.push(data);

        if(data){
            var len = data.query.results.Result.length;           
            var txt = "";
            if(len > 0){                 
                for(var i=0;i<len;i++){
                    if(true){                    
                        txt += "<tr><td>"+data.query.results.Result[i].Title+"</td><td>"+data.query.results.Result[i].Title+"</td></tr>";                      
                    }
                }               
                if(txt != ""){          

                    var tbody = document.querySelector("#list tbody");                    
                    tbody.appendChild(tbody.innerHTML=txt);
                   // tbody.innerHTML=txt;
                    //alert(txt);
                    //tr.innerHTML = txt;
                   // tbody.appendChild(tbody)

                }
            }
        }
        });
    }
});

通过使用下面的函数,我们可以将数据从JavaScript绑定到html表

var tbody = document.querySelector("#list tbody"); 添加表 IDtbody.appendChild(tbody.innerHTML=txt);