Problem with items.push - need string but getting object Object
This is part of my code. Maybe it is a little implicity but problem is easy to localize, i think. I want variable notions
to be something which when i add this i will add words of notions, not object Object
like i have now.
With this code i see that it makes good $link
as my links but i can't combine it to one <span>
element or something which could i use as notions
variable when i am pushin items by items.push
:
$.each(data, function(index, value) {
var notions = [];
var tags = data[0].extras.tags.replace(/[\[\]]/g, '').spli开发者_开发问答t(', ');
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 );
});
You're creating an object with $('<a/>')
then adding it to notions
. If you want the string, try getting the html of the object you created. That mess in items.push
is illegible.
精彩评论