In the original table.html, there is the following script section of code which adds rows dynamically into table:
âclipâ
function addRow(dom, tag) {
for(j=0;j<rowArray.length;j++){
var el = doc.createElement(tag);
el.innerHTML = rowArray[j];
tr.appendChild(el);
dom.appendChild(tr);
document.getElementById(tag).style.color = â#ff0000â;
}
}
âclapâ
Now, I tried to integrate your suggestion into that as follows:
âclipâ
function addRow(dom, tag) {
for(j=0;j<rowArray.length;j++){
var el = doc.createElement(tag);
el.innerHTML = rowArray[j];
tr.appendChild(el);
dom.appendChild(tr);
document.getElementById(tag).style.color = â#ff0000â;
âŚbut I get only empty WebViewer.
All parenthesis should match, at least in Notepad++ editor they do.
As I do not really know any html syntax, I am not sure what is the issue.
Should I distinguish these sentences and use either one of âdocument.getElementById(tag)â OR âdocument.querySelectorAll(âtdâ).forEachâ ?
Another try, did not succeed either:
âclipâ
function addRow(dom, tag) {
for(j=0;j<rowArray.length;j++) {
var el = doc.createElement(tag);
el.innerHTML = rowArray[j];
tr.appendChild(el);
dom.appendChild(tr);
document.getElementById(tag).style.color = â#ff0000â;
However, when I implemented the script section into table.html as follows, I get just an empty WebViewer. Without colors the result is however ok and works fine.
âclipâ
function addRow(dom, tag) {
for(j=0;j<rowArray.length;j++) {
var el = doc.createElement(tag);
el.innerHTML = rowArray[j];
tr.appendChild(el);
dom.appendChild(tr);
document.getElementById(tag).style.color = â#ff0000â;
}
}
document.querySelectorAll('td').forEach(e => {
if (e.textContent == "Alvin") {
e.style.color = "green";
}
else if (e.textContent == "Alan") {
e.style.color = "red";
}
else {
e.style.color = "black";
}
});
--clap--
And now Alvin resulted as green and Alan resulted as red in WebViewer.
Iâd recommend finding out what versions of Android your target audience typically uses and tailoring your JavaScript to only use APIs supported by those versions. Check out caniuse.com for more info.
yes do have that table.html working in my app.
But really? If I click on the table view (=WebViewer), it returns that row index inside the app?
Cannot be quite like that, because there is no such activity for Webviewer on blocks side.
So I have now misunderstood something�
Is this how it should go?
I tried this with emulator but the table row did not indicate in any way that it became âselectedââŚ
âclipâ
tr.addEventListener (âclickâ, function () {
// return picked row (remove td tag, use delimiter and remove last character, http://stackoverflow.com/a/1990274)
var picked = this.innerHTML.replace(/
// return index (add 1 because first row is the header row)
//window.document.title = this.rowIndex + 1;
window.AppInventor.setWebViewString(this.rowIndex + 1);
});
You will need to use the when webviewstring Changed event in the app to return the value of the row selected, then use this with the list you sent to the html file