简体   繁体   English

在参数列表后追加数据获取 Uncaught SyntaxError: missing )

[英]append data in datable getting Uncaught SyntaxError: missing ) after argument list

$("#searchresult").append("<tr><td id=''>" + data[i].landarp + "</td>" + "<td id=''>" + data[i].landarp + "</td>" + "<td id=''>" + data[i].landpin + "</td>" + "<td id=''>" + (data[i].landlot ? "Lot " + data[i].landlot : "") + "/" + (data[i].landblock ? "Block " + data[i].landblock : "") + "</td>" + "<td id=''>" + data[i].landfirstname + " " + data[i].landmiddlename + " " + data[i].landlastname + ", " + data[i].landsuffix + "</td>"
    for (var land = 0; land < landaddress.length; land++) {
        landownercontactflag = landaddress[land].landownercontactflag;
        landownercontactflag === "1" ? (contactaddress = landaddress[land].landownerprovince + " " + landaddress[land].landownermunicipality + " " + landaddress[land].landownerbarangay + ", " + landaddress[land].landownerstreet) : (homeaddress = landaddress[land].landownerprovince + " " + landaddress[land].landownermunicipality + " " + landaddress[land].landownerbarangay + ", " + landaddress[land].landownerstreet) + "<td id=''>" + landownercontactflag === "1" ? contactaddress : homeaddress + "</td>"
    } + "<td id=''>" + data[i].landyear + "</td>" + "<td id=''>" + "<a class=\"af_rpta_treasuryall_specificpin\"  id=" + data[i].landpin + " href='#' >View Details</a>" + "</td></tr>");

Trying to append data from database using this code but then i get Uncaught SyntaxError: missing ) after argument list in this line +"<td id=''>" + data[i].landfirstname + " " + data[i].landmiddlename + " " + data[i].landlastname + ", " + data[i].landsuffix + "</td>" what is the cause of this and how to fix it尝试使用此代码从数据库中附加数据,但随后在此行中的Uncaught SyntaxError: missing ) after argument list +"<td id=''>" + data[i].landfirstname + " " + data[i].landmiddlename + " " + data[i].landlastname + ", " + data[i].landsuffix + "</td>"这是什么原因以及如何解决

If you remove all the data specific parts, this is what you have:如果您删除所有数据特定部分,这就是您所拥有的:

$("#searchresult").append("text"
for (var land = 0; land < landaddress.length; land++) {
    landownercontactflag = "text";
} 
+ "text");

I am not missing a ")" i checked it thoroughly i think its because of for loop inside append just like comment above我没有遗漏一个“)”我彻底检查了它我认为这是因为 append 里面的 for 循环就像上面的评论一样

There's a missing ")" at the end of the append("text"在 append("text"

(you'll also notice I've changed the indentation to how it's interpreted) (您还会注意到我已将缩进更改为它的解释方式)

Javascript does not require the use of ";" Javascript 不需要使用“;” to end statements and you can use a newline to mean the same, ie these are equivalent:结束语句,您可以使用换行符来表示相同的意思,即这些是等效的:

$("#").append()

and

$("#").append();

because there's a newline at the end of the append( , it looks to see what the next statement is. If this was a '+' it would continue to append the next text, but in this case, it's a new statement for - so javascript attempts to close off the .append( and gives an error that there's a missing ")".因为有在结束一个新行append( ,它看起来看下面的语句是什么?如果这是一个“+”,将继续下一个文本追加,但在这种情况下,这是一个新的说法。 for -所以javascript 尝试关闭.append(并给出缺少“)”的错误。

This is the equivalent of:这相当于:

$("#searchresult").append("text";
for ...

see the ";"见“;” at the end now?现在到底? As there's no ")" before the implied ";", it gives you the warning that there's a ")" missing.由于在隐含的“;”之前没有“)”,它会警告您缺少“)”。

If you did add the ');'如果您确实添加了 ');' at the end of the line then you'll get an error later on about the + .. as there's nothing for the + to be +ed to.在该行的末尾,那么你将在后面约得到一个错误的+ ..因为没有什么的+是+ ED来。

As you've established, this is because of trying to put a command inside the brackets of another - but I wanted to explain why the interpreter thinks this way with the implied end-of-statement at a newline.正如您已经确定的那样,这是因为试图将一个命令放在另一个的括号内 - 但我想解释为什么解释器会在换行符处以隐含的语句结束的方式思考。

You can't put a for statement inside a $("#searchresult").append(您不能将for语句放在$("#searchresult").append(

My suggestion is to create a variable and to populate it... then to use it inside append.我的建议是创建一个变量并填充它......然后在 append 中使用它。

For example:例如:

var myVar = "<tr><td id=''>" + data[i].landarp + "</td>" + "<td id=''>" + data[i].landarp
...
for (var land = 0; land < landaddress.length; land++) {
  landownercontactflag = landaddress[land].landownercontactflag;
  ....
  myVar = myVar + ......
  .....
}
....
$("#searchresult").append(myVar);

But... are you sure you really know what your "for" loop is doing?但是......你确定你真的知道你的“for”循环在做什么?

UPDATE: as alternative (without a variable):更新:作为替代(没有变量):

 $("#searchresult").append("<tr><td id=''>" + data[i].landarp + "</td>" + "<td id=''>" + data[i].landarp ....);
    ...
    for (var land = 0; land < landaddress.length; land++) {
      landownercontactflag = landaddress[land].landownercontactflag;
      ....
      $("#searchresult").append(".....");
    }
    ....
    $("#searchresult").append("....");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM