jsTree - is_parent() returning wrong value
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm requesting data from a remote server with json return in format :
[
{"id":"1", "parent": "#", "text" : "Parent1"},
{"id":"2", "parent": 1, "text" : "Child1"}
{"id":"3", "parent": 2, "text" : "Child12"}
{"id":"4", "parent": 1, "text" : "Child2"}
{"id":"5", "parent": 1, "text" : "Child3"}
{"id":"6", "parent": 4, "text" : "Child21"}
]
I would like to check if the selected node is a parent. I use this code:
$('#treeview').on("select_node.jstree", function (e, data) {
var isParent = data.instance.is_parent();
alert(isParent)
});
It always returns false even when I click on PARENT.
What am I missing here ?
UPDATE
This is how I get solved the issue. But I still wonder why the methods is_parent()
and is_leaf()
are not working
var isParent = (data.node.children.length > 0);
javascript json jstree
add a comment |
I'm requesting data from a remote server with json return in format :
[
{"id":"1", "parent": "#", "text" : "Parent1"},
{"id":"2", "parent": 1, "text" : "Child1"}
{"id":"3", "parent": 2, "text" : "Child12"}
{"id":"4", "parent": 1, "text" : "Child2"}
{"id":"5", "parent": 1, "text" : "Child3"}
{"id":"6", "parent": 4, "text" : "Child21"}
]
I would like to check if the selected node is a parent. I use this code:
$('#treeview').on("select_node.jstree", function (e, data) {
var isParent = data.instance.is_parent();
alert(isParent)
});
It always returns false even when I click on PARENT.
What am I missing here ?
UPDATE
This is how I get solved the issue. But I still wonder why the methods is_parent()
and is_leaf()
are not working
var isParent = (data.node.children.length > 0);
javascript json jstree
see stackoverflow.com/questions/30782213/…
– Tamil Selvan C
Nov 23 '18 at 7:00
@TamilSelvanC I checked the link before but usingvar isParent = data.instance.is_parent(); alert(isParent)
does not solve the problem
– Kwaye Kant
Nov 23 '18 at 7:13
Hi, i updated my answer. Please check
– Tamil Selvan C
Nov 23 '18 at 7:28
I got it. Thanks
– Kwaye Kant
Nov 23 '18 at 8:13
add a comment |
I'm requesting data from a remote server with json return in format :
[
{"id":"1", "parent": "#", "text" : "Parent1"},
{"id":"2", "parent": 1, "text" : "Child1"}
{"id":"3", "parent": 2, "text" : "Child12"}
{"id":"4", "parent": 1, "text" : "Child2"}
{"id":"5", "parent": 1, "text" : "Child3"}
{"id":"6", "parent": 4, "text" : "Child21"}
]
I would like to check if the selected node is a parent. I use this code:
$('#treeview').on("select_node.jstree", function (e, data) {
var isParent = data.instance.is_parent();
alert(isParent)
});
It always returns false even when I click on PARENT.
What am I missing here ?
UPDATE
This is how I get solved the issue. But I still wonder why the methods is_parent()
and is_leaf()
are not working
var isParent = (data.node.children.length > 0);
javascript json jstree
I'm requesting data from a remote server with json return in format :
[
{"id":"1", "parent": "#", "text" : "Parent1"},
{"id":"2", "parent": 1, "text" : "Child1"}
{"id":"3", "parent": 2, "text" : "Child12"}
{"id":"4", "parent": 1, "text" : "Child2"}
{"id":"5", "parent": 1, "text" : "Child3"}
{"id":"6", "parent": 4, "text" : "Child21"}
]
I would like to check if the selected node is a parent. I use this code:
$('#treeview').on("select_node.jstree", function (e, data) {
var isParent = data.instance.is_parent();
alert(isParent)
});
It always returns false even when I click on PARENT.
What am I missing here ?
UPDATE
This is how I get solved the issue. But I still wonder why the methods is_parent()
and is_leaf()
are not working
var isParent = (data.node.children.length > 0);
javascript json jstree
javascript json jstree
edited Nov 23 '18 at 8:12
Kwaye Kant
asked Nov 23 '18 at 6:33
Kwaye KantKwaye Kant
3616
3616
see stackoverflow.com/questions/30782213/…
– Tamil Selvan C
Nov 23 '18 at 7:00
@TamilSelvanC I checked the link before but usingvar isParent = data.instance.is_parent(); alert(isParent)
does not solve the problem
– Kwaye Kant
Nov 23 '18 at 7:13
Hi, i updated my answer. Please check
– Tamil Selvan C
Nov 23 '18 at 7:28
I got it. Thanks
– Kwaye Kant
Nov 23 '18 at 8:13
add a comment |
see stackoverflow.com/questions/30782213/…
– Tamil Selvan C
Nov 23 '18 at 7:00
@TamilSelvanC I checked the link before but usingvar isParent = data.instance.is_parent(); alert(isParent)
does not solve the problem
– Kwaye Kant
Nov 23 '18 at 7:13
Hi, i updated my answer. Please check
– Tamil Selvan C
Nov 23 '18 at 7:28
I got it. Thanks
– Kwaye Kant
Nov 23 '18 at 8:13
see stackoverflow.com/questions/30782213/…
– Tamil Selvan C
Nov 23 '18 at 7:00
see stackoverflow.com/questions/30782213/…
– Tamil Selvan C
Nov 23 '18 at 7:00
@TamilSelvanC I checked the link before but using
var isParent = data.instance.is_parent(); alert(isParent)
does not solve the problem– Kwaye Kant
Nov 23 '18 at 7:13
@TamilSelvanC I checked the link before but using
var isParent = data.instance.is_parent(); alert(isParent)
does not solve the problem– Kwaye Kant
Nov 23 '18 at 7:13
Hi, i updated my answer. Please check
– Tamil Selvan C
Nov 23 '18 at 7:28
Hi, i updated my answer. Please check
– Tamil Selvan C
Nov 23 '18 at 7:28
I got it. Thanks
– Kwaye Kant
Nov 23 '18 at 8:13
I got it. Thanks
– Kwaye Kant
Nov 23 '18 at 8:13
add a comment |
1 Answer
1
active
oldest
votes
To get parent
use
var isParent = (data.node.children.length > 0);
alert(isParent );
$('#treeview').jstree({
'core': {
'data': [{
"id": "1",
"parent": "#",
"text": "Parent1"
}, {
"id": "2",
"parent": 1,
"text": "Child1"
},
{
"id": "21",
"parent": 2,
"text": "Child1"
},
{
"id": "3",
"parent": 2,
"text": "Child12"
}, {
"id": "4",
"parent": 1,
"text": "Child2"
}, {
"id": "5",
"parent": 1,
"text": "Child3"
},
{
"id": "6",
"parent": 4,
"text": "Child21"
},
{
"id": "7",
"parent": '#',
"text": "Parent 2"
},
{
"id": "8",
"parent": 7,
"text": "Child"
}
]
}
});
$('#treeview').on("select_node.jstree", function(e, data) {
// var isParent = data.instance.is_parent(data);
// If you need to check if a node is a root node you can use:
var isParent = (data.node.children.length > 0);
console.log(data.node);
alert(isParent)
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeview"></div>
Thank you for your reply @Tamil but this does not solve the problem. It only works on root nodes.For any node in the tree I want to know if it is a parent and then get all it's childreen
– Kwaye Kant
Nov 23 '18 at 7:10
1
tryvar isParent = (data.node.children.length > 0); alert(isParent );
– Tamil Selvan C
Nov 23 '18 at 7:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441642%2fjstree-is-parent-returning-wrong-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To get parent
use
var isParent = (data.node.children.length > 0);
alert(isParent );
$('#treeview').jstree({
'core': {
'data': [{
"id": "1",
"parent": "#",
"text": "Parent1"
}, {
"id": "2",
"parent": 1,
"text": "Child1"
},
{
"id": "21",
"parent": 2,
"text": "Child1"
},
{
"id": "3",
"parent": 2,
"text": "Child12"
}, {
"id": "4",
"parent": 1,
"text": "Child2"
}, {
"id": "5",
"parent": 1,
"text": "Child3"
},
{
"id": "6",
"parent": 4,
"text": "Child21"
},
{
"id": "7",
"parent": '#',
"text": "Parent 2"
},
{
"id": "8",
"parent": 7,
"text": "Child"
}
]
}
});
$('#treeview').on("select_node.jstree", function(e, data) {
// var isParent = data.instance.is_parent(data);
// If you need to check if a node is a root node you can use:
var isParent = (data.node.children.length > 0);
console.log(data.node);
alert(isParent)
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeview"></div>
Thank you for your reply @Tamil but this does not solve the problem. It only works on root nodes.For any node in the tree I want to know if it is a parent and then get all it's childreen
– Kwaye Kant
Nov 23 '18 at 7:10
1
tryvar isParent = (data.node.children.length > 0); alert(isParent );
– Tamil Selvan C
Nov 23 '18 at 7:29
add a comment |
To get parent
use
var isParent = (data.node.children.length > 0);
alert(isParent );
$('#treeview').jstree({
'core': {
'data': [{
"id": "1",
"parent": "#",
"text": "Parent1"
}, {
"id": "2",
"parent": 1,
"text": "Child1"
},
{
"id": "21",
"parent": 2,
"text": "Child1"
},
{
"id": "3",
"parent": 2,
"text": "Child12"
}, {
"id": "4",
"parent": 1,
"text": "Child2"
}, {
"id": "5",
"parent": 1,
"text": "Child3"
},
{
"id": "6",
"parent": 4,
"text": "Child21"
},
{
"id": "7",
"parent": '#',
"text": "Parent 2"
},
{
"id": "8",
"parent": 7,
"text": "Child"
}
]
}
});
$('#treeview').on("select_node.jstree", function(e, data) {
// var isParent = data.instance.is_parent(data);
// If you need to check if a node is a root node you can use:
var isParent = (data.node.children.length > 0);
console.log(data.node);
alert(isParent)
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeview"></div>
Thank you for your reply @Tamil but this does not solve the problem. It only works on root nodes.For any node in the tree I want to know if it is a parent and then get all it's childreen
– Kwaye Kant
Nov 23 '18 at 7:10
1
tryvar isParent = (data.node.children.length > 0); alert(isParent );
– Tamil Selvan C
Nov 23 '18 at 7:29
add a comment |
To get parent
use
var isParent = (data.node.children.length > 0);
alert(isParent );
$('#treeview').jstree({
'core': {
'data': [{
"id": "1",
"parent": "#",
"text": "Parent1"
}, {
"id": "2",
"parent": 1,
"text": "Child1"
},
{
"id": "21",
"parent": 2,
"text": "Child1"
},
{
"id": "3",
"parent": 2,
"text": "Child12"
}, {
"id": "4",
"parent": 1,
"text": "Child2"
}, {
"id": "5",
"parent": 1,
"text": "Child3"
},
{
"id": "6",
"parent": 4,
"text": "Child21"
},
{
"id": "7",
"parent": '#',
"text": "Parent 2"
},
{
"id": "8",
"parent": 7,
"text": "Child"
}
]
}
});
$('#treeview').on("select_node.jstree", function(e, data) {
// var isParent = data.instance.is_parent(data);
// If you need to check if a node is a root node you can use:
var isParent = (data.node.children.length > 0);
console.log(data.node);
alert(isParent)
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeview"></div>
To get parent
use
var isParent = (data.node.children.length > 0);
alert(isParent );
$('#treeview').jstree({
'core': {
'data': [{
"id": "1",
"parent": "#",
"text": "Parent1"
}, {
"id": "2",
"parent": 1,
"text": "Child1"
},
{
"id": "21",
"parent": 2,
"text": "Child1"
},
{
"id": "3",
"parent": 2,
"text": "Child12"
}, {
"id": "4",
"parent": 1,
"text": "Child2"
}, {
"id": "5",
"parent": 1,
"text": "Child3"
},
{
"id": "6",
"parent": 4,
"text": "Child21"
},
{
"id": "7",
"parent": '#',
"text": "Parent 2"
},
{
"id": "8",
"parent": 7,
"text": "Child"
}
]
}
});
$('#treeview').on("select_node.jstree", function(e, data) {
// var isParent = data.instance.is_parent(data);
// If you need to check if a node is a root node you can use:
var isParent = (data.node.children.length > 0);
console.log(data.node);
alert(isParent)
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeview"></div>
$('#treeview').jstree({
'core': {
'data': [{
"id": "1",
"parent": "#",
"text": "Parent1"
}, {
"id": "2",
"parent": 1,
"text": "Child1"
},
{
"id": "21",
"parent": 2,
"text": "Child1"
},
{
"id": "3",
"parent": 2,
"text": "Child12"
}, {
"id": "4",
"parent": 1,
"text": "Child2"
}, {
"id": "5",
"parent": 1,
"text": "Child3"
},
{
"id": "6",
"parent": 4,
"text": "Child21"
},
{
"id": "7",
"parent": '#',
"text": "Parent 2"
},
{
"id": "8",
"parent": 7,
"text": "Child"
}
]
}
});
$('#treeview').on("select_node.jstree", function(e, data) {
// var isParent = data.instance.is_parent(data);
// If you need to check if a node is a root node you can use:
var isParent = (data.node.children.length > 0);
console.log(data.node);
alert(isParent)
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeview"></div>
$('#treeview').jstree({
'core': {
'data': [{
"id": "1",
"parent": "#",
"text": "Parent1"
}, {
"id": "2",
"parent": 1,
"text": "Child1"
},
{
"id": "21",
"parent": 2,
"text": "Child1"
},
{
"id": "3",
"parent": 2,
"text": "Child12"
}, {
"id": "4",
"parent": 1,
"text": "Child2"
}, {
"id": "5",
"parent": 1,
"text": "Child3"
},
{
"id": "6",
"parent": 4,
"text": "Child21"
},
{
"id": "7",
"parent": '#',
"text": "Parent 2"
},
{
"id": "8",
"parent": 7,
"text": "Child"
}
]
}
});
$('#treeview').on("select_node.jstree", function(e, data) {
// var isParent = data.instance.is_parent(data);
// If you need to check if a node is a root node you can use:
var isParent = (data.node.children.length > 0);
console.log(data.node);
alert(isParent)
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeview"></div>
edited Nov 23 '18 at 7:28
answered Nov 23 '18 at 6:52
Tamil Selvan CTamil Selvan C
14.7k93659
14.7k93659
Thank you for your reply @Tamil but this does not solve the problem. It only works on root nodes.For any node in the tree I want to know if it is a parent and then get all it's childreen
– Kwaye Kant
Nov 23 '18 at 7:10
1
tryvar isParent = (data.node.children.length > 0); alert(isParent );
– Tamil Selvan C
Nov 23 '18 at 7:29
add a comment |
Thank you for your reply @Tamil but this does not solve the problem. It only works on root nodes.For any node in the tree I want to know if it is a parent and then get all it's childreen
– Kwaye Kant
Nov 23 '18 at 7:10
1
tryvar isParent = (data.node.children.length > 0); alert(isParent );
– Tamil Selvan C
Nov 23 '18 at 7:29
Thank you for your reply @Tamil but this does not solve the problem. It only works on root nodes.For any node in the tree I want to know if it is a parent and then get all it's childreen
– Kwaye Kant
Nov 23 '18 at 7:10
Thank you for your reply @Tamil but this does not solve the problem. It only works on root nodes.For any node in the tree I want to know if it is a parent and then get all it's childreen
– Kwaye Kant
Nov 23 '18 at 7:10
1
1
try
var isParent = (data.node.children.length > 0); alert(isParent );
– Tamil Selvan C
Nov 23 '18 at 7:29
try
var isParent = (data.node.children.length > 0); alert(isParent );
– Tamil Selvan C
Nov 23 '18 at 7:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441642%2fjstree-is-parent-returning-wrong-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
see stackoverflow.com/questions/30782213/…
– Tamil Selvan C
Nov 23 '18 at 7:00
@TamilSelvanC I checked the link before but using
var isParent = data.instance.is_parent(); alert(isParent)
does not solve the problem– Kwaye Kant
Nov 23 '18 at 7:13
Hi, i updated my answer. Please check
– Tamil Selvan C
Nov 23 '18 at 7:28
I got it. Thanks
– Kwaye Kant
Nov 23 '18 at 8:13