第一次单击按钮时,它不会将数据绑定到表中
For the first time button click it is not binding data into table,
第一次单击按钮时,它不会将数据绑定到表中,第二次单击后它再次被绑定。我需要绑定数据以进行首次点击
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);
相关文章:
- 在VanillaJS中模拟模型双向数据绑定
- Telerik rad组合框多列数据绑定
- 数据绑定:'系统Char'不包含名为'xxxxx'
- OnsenUI AngularJS数据绑定无法正常工作
- Ionic-item在导航栏中进行双向数据绑定
- 基本D3.js:如何将具有其他属性的数据绑定到元素
- 使用自定义数据属性或将数据绑定到处理程序来处理事件
- ListView的ItemTemplate内的自定义HtmlControl的数据绑定失败
- $http中的Angular 1数据绑定承诺不起作用
- 在何处和何时添加具有数据绑定的元素
- 使用AngularJs数据绑定的三元运算符显示图像
- 数据绑定禁用属性在 foreach 内的按钮中不起作用
- AngularJS数据绑定到按钮不起作用
- 来自单选按钮angularjs的数据绑定
- 将数据绑定到中继器控件中onclientclick()的链接按钮
- js:当按钮被点击时,调用一个带有数据绑定参数的函数
- 在knockout js中,选中的数据绑定对单选按钮不起作用
- 删除映射和foreach数据绑定表上的按钮,缺少对视图模型的引用
- 获取html表中按钮的数据绑定值
- 第一次单击按钮时,它不会将数据绑定到表中