문제

i want to dynamically create a table some of them having links to some other url with a loop, note: inside each i am filling dynamic html which has dynamic values that are filled from an array.My code is given bellow . When i run this code js returns an array "unexpected tocken 'for'" , I tried it with while also ..The error is same again. Help me out freaks..

html += '<tr class="' + (i % 2 == 0 ? 'grid_color' : '') + '" data-type="record"  data-record-id="' + records[i].id + '" data-row-index="' + i + '">'

+ '<td data-table-col="16" title="' + Samples.htmlEntities(records[i].name_id) + '">' +
for (i = 0; i < nameSplit.length; i++) {
    if (nameSplit[i] != "None") {
        name = nameSplit[i].split(".");
        name = name.shift();
        '<a target = "_blank" href="http://www.google.com/' + name + '">' + name.substr(0, 10 / nameSplit.length) + (name.length > 10 / nameSplit.length ? '...' : '') + '</a>'
    } else {
        if (i != nameSplit.length - 1) {
            "|";
        }
    } else {
        if (i != nameSplit.length - 1) "None".concat("|");
        else "None";
    }
}
}
'</td>'
도움이 되었습니까?

해결책

I tried fixing your code indentation and format but it was just unreadable for me. But anyway, I'll do it as an example you adapt it to your specific needs.

var html = "<table>";
for(var i = 0; i<someCondition; i++){
  html +="<tr><td>Cell 1</td><td>Cell 2</td><tr>";
}
html += "</table>";

the error you are getting is because somewhere in your code you have something like ... + for(...) and that doesn't work, a for loop doesn't return so it won't get anything from it.

다른 팁

You cannot do it that way. If your'e adding strings together, strings are expected. If you write code at that point, it's seen as in invalid string, rather than code that will generate the actual string.

You need to put all of the script before the part where you append strings to 'html'.
If you wrote this directly into the html source code (which is a horrible approach to it), you should read about the basics of applying scripts (I guess you're more experienced than that, though).

So: put script before the "html + A + B + ...".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top