Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Am new to jQuery and javaScript.

How can I (1) extract a data item and (2) concatenate it to a string below.

This working sample below works and demonstrates how "alexLink" contains the data I want.

JavaScript
window.open(data.node.data.alexLink, "_blank");


I want to take alexLink contents and concatenate them into the following javaScript (call to python) statement. You don't have to know how this link works as I just want the syntax for concatenating the content, which is a URL.

ajax("{{=URL('default', INSUERT_CONTENTS_HERE)}}", [], ':eval');


when I try to view the contents alert(data.node.data.alexLink) I see nothing.

To clarify the problem, I don't want var = string1.concat(string2)

Instead want the line to read: "text".concat(string1) + .concat(additional_text)

is that possible in javaScript (not using the "var =")?

thanks,

Alex Glaros

JavaScript
<script type="text/javascript">

// Initialize Fancytree
	$("#alexTree").fancytree({
		checkbox: true,
		selectMode: 3,
		source: {url: tree_url},
		dataType: "json",
		postProcess: function(event, data){
			data.result = convertData(data.response);
		},
		select: function(event, data) {
            ajax("{{=URL('default', 'navigate_to_txonomy_column', vars=dict(specificTaxonomyColumnID=specificTaxonomyColumnID))}}", [], ':eval');
		}
	});
});

</script>

{{## ajax line above used to be:  window.open(data.node.data.alexLink, "_blank");}}


What I have tried:

I've tried using the alert box to show the data but it came up blank.
Posted
Updated 15-Jun-16 9:10am
v4
Comments
Sergey Alexandrovich Kryukov 15-Jun-16 12:41pm    
#1: as any other data; the problem is not clear; #2: concatenation: var C = A + B.
Another #1: it depends on what data is; Another #2: same, from the JavaScript standpoint, there is only one type of string object; not matter if it is Python or not.
It's better not to use window.open, in most cases...
—SA
Alex Glaros 15-Jun-16 13:01pm    
to clarify the problem, I don't want var = string1.concat(string2)

Instead want the line to read: "text".concat(string1) + .concat(additional_text)

is that possible in javaScript (not using the "var =")?
ZurdoDev 15-Jun-16 13:35pm    
1. Reply to the comment so that the user is notified.
2. Concat is very simple. ajax("{{=URL('default', ' + data.node.data.alexLink + ')}}", [], ':eval');
However, if you are saying that alert(data.node.data.alexLink) is blank then concatenating it will only add an empty string.
Alex Glaros 15-Jun-16 14:10pm    
concat you provided works but I don't know how to reference the data. It's there because the window.open(data.node.data.alexLink) works correctly. Is there syntax for making it accessible? ...something (just guessing) like: xml(data.node.data.alexLink) ?

data comes from fancyTree (https://github.com/mar10/fancytree/wiki)
ZurdoDev 15-Jun-16 14:15pm    
You need to do some debugging. window.open takes a string, so
data.node.data.alexLink is a string. Otherwise window.open would not work. So, you'll have to debug your code to see what is happening.

http://www.w3schools.com/jsref/met_win_open.asp

1 solution

As mentioned in the comments you'll need to do some debugging if data.node.data.alexLink does not contain a value.

Concat is very simple. ajax("{{=URL('default', '" + data.node.data.alexLink + "')}}", [], ':eval');
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900