【发布时间】:2013-04-05 21:58:46
【问题描述】:
字符串连接有问题。我正在进行一系列 ajax 调用,并根据结果构建一个表,其中每个元素都有一个引导弹出框字段。在这个领域,我想展示更多的细节。代码如下:
...initiate ajax post ...
... other parameters...
function(data){//function called on success
var popoverContent = 'Sent: ';
popoverContent = popoverContent.concat(JSON.stringify(obj.value));
popoverContent = popoverContent.concat('\nReceived: ');
popoverContent = popoverContent.concat(JSON.stringify(data.error));
console.log(popoverContent);
... other processing ...
...building table...
'<td> <a class="btn large primary" rel="popover" data-content='+popoverContent+' data-original-title="Detailed description">'+outcome+'</a></td>'+ ...
...rest of the code ...
现在我的问题是,虽然在控制台中 popoverContent 包含我想以字符串形式显示的所有数据,但在弹出窗口中只有 Sent: 被显示。如果我使 popoverContent 等于任何其他连接的部分,它会显示该部分,但它不会显示整个内容。 我在这里错过了什么?
【问题讨论】:
-
.concat() 是一个用于连接两个数组而不是字符串的函数。
-
@DeckerWBrower - 不正确,还有一个String concat 方法
-
@MichaelGeary - 哦对不起我的错。出于明显的原因,我以前从未见过有人使用它。感谢您指出这一点
-
不用担心,它实际上也让我感到意外! MDN 绝对不推荐。
标签: javascript twitter-bootstrap popover