2011-09-19 134 views
0

這是我的代碼的一部分。也許這有點隱含,但我認爲問題很容易本地化。我想變量notions是什麼,當我添加這個我會添加概念的話,而不是像我現在object Object。 有了這個代碼,我看到,這是一個很好的$link作爲我聯繫,但我不能把它結合到一個<span>元素或東西時,我被items.push甩賣項目作爲notions變量,可以使用: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 + '&nbsp;&nbsp;'; 
       console.log($link); 
      } 
     });   

     items.push('<li style="border: 1px solid black; list-style-type: none" ' + 'id="' +   value.pk + '"' + 'name="' + value.fields.depth + '">' + 
      '&nbsp;&nbsp;<span class="zero">()</span>&nbsp;&nbsp;' +         
      '<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

你'$('<a/>')創建一個對象,然後將其添加到notions。如果您想要字符串,請嘗試獲取您創建的對象的html。 items.push中的這個混亂是難以辨認的。

+0

可以給我一些示例代碼嗎? – Cadilac

+0

不知道如何。但是,如果你想要一個字符串,你也可以......只是使用一個字符串,而不是創建一個元素。 –

+0

這不是一團糟,但它只是看起來像。 – Cadilac