我是淘汰js的新手,我正在尝试创建一个表,该表的数据来自使用php ajax的数据库。数据绑定不适用于ajax php结果,而如果我在同一页中使用数据绑定变量创建表它与该表一起工作。我如何使ajax结果与剔除一起工作。感谢您的帮助 以下是我的代码 数据加载php:
include("db.php");
$result=mysqli_query($conn,"select * from codes");
$par='\$parent';
echo '<table class="table table-striped box" >
<thead>
<tr>
<td align=center> <b>Code</b></td>
<td align=center><b>Starting Date</b></td>
<td align=center><b>Closing Date</b></td>
<td align=center><b>Select</b></td></tr></thead>
';
echo '<tbody data-bind="foreach:{data:rows,as:\'Row\'}">';
echo "<tr>
<td data-bind='text:Row.codes'></td>
<td data-bind='text:Row.sDate'></td>
<td data-bind='text:Row.eDate'></td>
<td align=center><button data-bind='click:$par.selectRow' class='btn btn-orange'>Select</button></td>
</tr>";
while($data = mysqli_fetch_row($result))
{
echo "<tr >";
echo "<td align=center data-bind='text:Row.codes'>$data[1]</td>";
echo "<td align=center data-bind='text:Row.sDate'>$data[2]</td>";
echo "<td align=center data-bind='text:Row.eDate'>$data[3]</td>";
echo "<td align=center><button data-bind='click:$par.selectRow' class='btn btn-orange addd'>Select</button></td>";
echo "</tr>";
}
echo "</tbody></table>";
和我要加载的ajax代码:
$(document).ready(function(){
$.ajax({
type:"POST",
url:"load.php",
dataType:"html",
success: function(response){
$("#codetable").html(response);
}
});
});
和我的淘汰赛脚本
$(document).ready(function(){
function Row(codes,sDate,eDate){
this.codes=codes;
this.sDate=sDate;
this.eDate=eDate;
}
var myRowViewModel = new function(){
var current= this;
this.SelectedRow = ko.observable(null);
this.rows=ko.observableArray([
new Row("45sd9e","10-08-2018",1000),
new Row("45sd9e","10-08-2018",1000),
]);
this.selectRow = function(Row){
current.SelectedRow(Row)
alert(Row.codes);
}
}
ko.applyBindings(myRowViewModel);
});
答案 0 :(得分:0)
现在我已经弄清楚了什么问题。我将数据更改为json并可以正常工作。