//anything inside 'pagebeforecreate' will execute just before this page is rendered to the user's screen
$(document).on("pagebeforecreate", function () {
printheader(); //print the header first before the user sees his page
});
$(document).ready(function () {
searchfriend();
function searchfriend() {
var url = serverURL() + "/getcategories.php";
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (arr) {
_getCategoryResult(arr);
},
error: function () {
validationMsg();
}
});
}
function _getCategoryResult(arr) {
var t; //declare variable t
//loop for the number of results found by getcategories.php
for (var i = 0; i < arr.length; i++) {
//add a new row
t.row.add([ //error
"<a href='#' class='ui-btn' id='btn" + arr[i].categoryID + "'>Category</a>" //add a new [Category] button
]).draw(false);
//We drew a [View] button. now bind it to some actions
$("#btn" + arr[i].categoryID).bind("click", { id: arr[i].categoryID }, function (event) {
var data = event.data;
showcategory(data.id); //when the user clicks on the [View] button, execute showcategory()
});
}
$("#categoryresult").show(); //show the results in the table searchresult
}
function showcategory(categoryID) {
//alert(categoryID);
window.location = "showuser.html?userid=" + userid;
}
});
第33行有一个错误:
&#34;未捕获的TypeError:无法读取属性&#39; row&#39;未定义&#34;
然而,似乎我不知道错误来自哪里。
无论如何我能解决这个问题吗?
答案 0 :(得分:0)
变量t
不是具有名为row
的属性的对象。
试试var t = { row: [] }
因此,您需要一个名为add
的方法的对象,并将该对象分配给t
答案 1 :(得分:0)
您似乎正在使用第三方jQuery插件DataTables。 遵循DataTables的用法。
var t; //declare variable t
应该是
var t = $("#categoryresult").DataTable();