One additional tweak to get the parent to (un)select the children. Please post an easier method if possible.
function
showSerializedData() {
var
chkBox = $(
this
)
var
serializedData = chkBox.serialize()
.replace(/%5B/g,
"["
)
.replace(/%5D/g,
"]"
)
.replace(/&/g,
"&"
);
//get the parent - typically a span
var
parent = chkBox.parent();
//check to be sure - we do not want to do closest as it will traverse to many items
if
(parent !=
null
&& chkBox.parent()[0].nodeName !=
'DIV'
)
{
//get the next item up - div.k-item, tells me this is a top node
parent = $(chkBox.parent()[0]).parent();
if
(parent !=
null
&& parent[0].nodeName ==
'DIV'
)
{
//get the children of the closest k-item (li) checkboxes
//select all
var
pBoxes = $(parent).closest(
'.k-item'
).find(
":checkbox"
);
if
(pBoxes.length > 0)
$(pBoxes).prop(
'checked'
,
this
.checked ?
"checked"
:
""
)
}
}
//check all child items for the current item
var
checkBoxes = chkBox.parent().find(
":checkbox"
);
if
(checkBoxes.length > 0)
$(checkBoxes).prop(
'checked'
,
this
.checked ?
"checked"
:
""
)
//gt the value...
var
value = chkBox.val();
//do something with it
$(
"#checked-nodes"
).html(serializedData);
}
enjoy!!!