这是我的代码的一部分。也许这有点不透明,但我认为问题很容易本地化。我希望变量notions
成为我添加此内容的东西,我将添加概念词,而不是像现在这样object Object
。
使用此代码,我看到它很好$link
作为我的链接,但我不能将它与一个<span>
元素或我可以用作notions
变量的东西组合,当我是pushin项目时items.push
:
$.each(data, function(index, value) {
var notions = [];
var tags = data[0].extras.tags.replace(/[\[\]]/g, '').split(', ');
var id = data[0].pk
$.each(tags, function(i,v){
var tag = v.match(/<Tag:\s(.*)>/);
if(tag !== null){
var href = '/notion/';
var $link = $('<a/>').attr('href', href+tag[1]).text(tag[1]);
notions = notions + $link + ' ';
console.log($link);
}
});
items.push('<li style="border: 1px solid black; list-style-type: none" ' + 'id="' + value.pk + '"' + 'name="' + value.fields.depth + '">' +
' <span class="zero">()</span> ' +
'<a href="' + value.extras.get_absolute_url_for_user + '">' +
'<span style="font-family: Trebuchet MS,Liberation San; font-size: 125%">' + value.fields.title + '</span></a> <br />' +
'<a href="' + value.extras.get_my_url + '">' +
'<p style="vertical-align: middle; margin-bottom: 0; margin-top: 0">' +
'<img style="cursor: pointer; vertical-align: middle" src="' + MEDIA_URL +
'own/i2.png" title="Show this in 1"></a>' +
'<img class="delete_item" name="' + value.pk + '"' +
'" style="cursor: pointer; vertical-align: middle" src="' + MEDIA_URL +
'own/minus.png" title="Delete this">' +
'<img class="get_item_form" name="' + value.pk +
'" style="cursor: pointer; vertical-align: middle" src="' + MEDIA_URL +
'own/plus.png" title="Add item">' +
notions +
'</p></li>');
$( '<ul/>', { html: items.join('') } ).insertAfter( nevermind );
});
答案 0 :(得分:0)
您正在使用$('<a/>')
创建对象,然后将其添加到notions
。如果你想要字符串,请尝试获取你创建的对象的html。 items.push
中的混乱是难以理解的。