后面的代码:
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(GetType(), "MyKey", "CreateNotificationTree(" + UserId + ")", true);
}
.js 文件:
function CreateNotificationTree(UserId)
{
var data = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "../api/notifications/byuserid/" + UserId,
contentType: "application/json"
}
},
schema: {
model: {
children: "notifications"
}
}
});
$("#treeview").kendoTreeView({
dataSource: data,
loadOnDemand: true,
checkboxes: {
checkChildren: true
},
dataTextField: ["notificationType", "NotificationDesc"]
});
}
标记(我需要这个吗?):
<script type="text/javascript">
$(document).ready(CreateNotificationTree(UserId));
</script>
这是行不通的。树视图未加载到页面上。