I am working on a dynamic query system. Simply, the user makes search with different parameters and the query results are dynamically changing based on these parameters.I am showing the results in a table. One option of the system is showing documents (pdfs). When the user clicks the document name, pdf file is opened.Following code works fine for the purpose.
function displayResults_document(pElmt) {
var table = pElmt.append("table").attr("class", "result-table");
var tr = table.append("tr").attr("id", "row1");
// Document Name
tr.append("td").append("h4").append("a").attr("href", function (d) {
if (d.attributes.link) {
return d.attributes.link;
} else {
return "#";
}
})
.text(function (d) {
return d.attributes.name;
});
}
One of the other results of the query are emails. What I want is, when the user clicks the email address, outlook (or other email app) opens with the clicked address to send the email. Here is what I did up to now (similar the code above). I tried the selected email address by replacing %s
function displayResults_email(pElmt) {
var table = pElmt.append("table").attr("class", "result-table");
var tr = table.append("tr").attr("id", "row1");
//Email Queried List
tr.append("td").append("h4").append("a").attr("href", function(d) {
var prefix = "mailto:%s";
var query_results = d.attributes.email1;
var end_result = prefix.replace("%s", query_results);
return end_result;
}).text(function (d){
return d.attributes.email1;
});
}
With the code above, it logs mailto:undefined
I think I need to pass the variable as global or sth? Although my several trials, I couldn't do that.. Any suggestions appreciated. Thanks
Allright, sometimes a short break and a little fresh air helps to see small mistakes.. Following code solves my problem. Hope someone else benefits also..
function displayResults_email(pElmt) {
var table = pElmt.append("table").attr("class", "result-table");
var tr = table.append("tr").attr("id", "row1");
// Email
tr.append("td").append("h4").append("a").attr("href", function (d) {
var prefix = "mailto:%s";
var query_result = d.attributes.email1;
var end_result = prefix.replace("%s", query_result);
return end_result;
}).text(function (d) {
return d.attributes.email1;
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.