チェックボックステンプレートを使用して剣道ツリービューを作成しています。
私のhtmlコード
<div id="treeview-left" style=" height: 375px; position: absolute;top: 30px;"></div>
次のようにツリービューを定義しました。
var treeview1 = $('#treeview-left').kendoTreeView({
select: onSelect,
checkboxTemplate: kendo.template($("#treeview-checkbox-template").html()),
dragAndDrop: true,
dataSource: parent,
dataTextField: ["parentName", "childName"]
}).data("kendoTreeView");
そして、チェックボックス テンプレートは次のように定義されます。
<script id="treeview-checkbox-template" type="text/kendo-ui-template">
<input type="checkbox" />
</script>
そしてデータソースは
var parent = new kendo.data.HierarchicalDataSource({
type: "POST",
dataType: "json",
transport: {
read: {
url: "/Projects/leftdisplay"
}
},
schema: {
model: {
id: "parentid",
hasChildren: "childName",
children: child
}
}
});
親の子は次のようになります。
var child = {
type: "POST",
dataType: "json",
transport: {
read: {
url: function (options) {
return kendo.format("/projects/modulesleftdisplay?parentid=" + options.parentid + "&roleid=" + rolevalue + "&projectid=" + projectid + "");
}
}
},
schema: {
model: {
id: "childid",
hasChildren: function () {
return false;
}
}
}
};
子のチェックボックスをクリックすると、選択した子の親 ID を取得したいと考えています。どうすればそれを取得できますか。
私は次のようなコードを書きました
$("#treeview-left [type=checkbox]").live('change', function (e) {
var chkBox = $(this)
var parentid = chkBox.parent();
var date = $('#treeview-left').data('kendoTreeView').dataItem(parent_id);
var parid = date.id;
var childid = $('#treeview-left').data('kendoTreeView').dataItem(parentid);
});
しかし、パリッドは得られていません。選択した子の親 ID を取得するにはどうすればよいですか。どんな助けでも大歓迎です。