0

チェックボックステンプレートを使用して剣道ツリービューを作成しています。

私の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 を取得するにはどうすればよいですか。どんな助けでも大歓迎です。

4

2 に答える 2

0

これを試して:

// Find all the checkboxes:
var checkboxes = Array.prototype.slice.call(document.querySelectorAll('#yourFormsID input[type=checkbox]'));

checkboxes.forEach(function(checkbox) {                //<== loop through checkboxes
    checkbox.addEventListener('change', function() {   //<== When clicked:
        console.log(this.parentNode.id);               //<== Log the id of the checkbox's parentNode in the console.
    }, false);
});

これがデモです。必ずコンソールを開いてください。

于 2013-03-14T05:12:33.320 に答える
0

あなたはこれを使うことができます

   var parentId = $(this).parent().closest(parent element).attr('id')

例:

 var parentId  = $(this).parent().closest('li').attr('id')

それ以外の

 var chkBox = $(this)

 var parentid = chkBox.parent();

親IDを取得します。

于 2013-03-14T05:15:12.800 に答える