JavaScript模板附加

时间:2014-04-28 03:21:14

标签: javascript jquery mustache

您好我正在使用jQuery Ajax来实现" GET" " XML"数据,
我正试图"追加"数据为"模板"。

我正试图追加标题:

   <div class="btn-group" style="margin:5px">
      <img class="img-swap2" data-toggle="dropdown" src="images/drop-down-btn_2.png">
     <a href="#">Title</a>
    </div>

附加图片/描述:

<img src="images/toggle-on.png" class="img-swap"/>
<a class="pull-left" href="#"></a>
   <div class="media-body" style>
       <div class="media">
          <a class="pull-left" href="#">                
             <img class="media-object" src="images/Penguins.jpg"></a>
           <div class="media-body">
             <textarea class="form-control" rows="4" readonly>Description..</textarea>
           </div>
       </div>
   </div>

追加代码:

var html = title + thumbnailUrl + description

var title = $(cur).find("title").text();
var thumbnailUrl = $(cur).find("thumbnailUrl").text();
var description = $(cur).find("description").text();

var $l = $mainStoryList;
$l.append(html);

1 个答案:

答案 0 :(得分:0)

标题,说明,thumbnailUrl class selectors 表示与此 dot(.) 进行说明

var title = $(cur).find(".title").text();
var thumbnailUrl = $(cur).find(".thumbnailUrl").text();
var description = $(cur).find(".description").text();

假设一切都 id selector 意味着在此之前加上 #

var title = $(cur).find("#title").text();
var thumbnailUrl = $(cur).find("#thumbnailUrl").text();
var description = $(cur).find("#description").text();