jasonmoo / t.js

A tiny javascript templating framework in ~400 bytes gzipped
MIT License
825 stars 88 forks source link

Uncaught TypeError: Cannot use 'in' operator to search for 'url' in undefined #13

Closed smarttang closed 9 years ago

smarttang commented 9 years ago

td is can't use.

{{@spiders}} {{/@spiders}}
爬虫URL爬取状态页面状态
{{=_val.url}}

function read_convent_task_report(task_id) { var _dom=$('.convent-report').html();

$.ajax({
    type: 'POST',
    url: CONVENT_REPORT_SOURCE,
    dataType: 'json',
    data: {'conventid':task_id},
    error: function(){
        console.log('read convent report error!');
    },
    success: function(msg){
        var template = new t(_dom);
        _readModal('查看报告',template.render(msg['data']),1);
    }
});

}

zhuangya commented 9 years ago

maybe wrap all your code in code block ?

FYI: https://guides.github.com/features/mastering-markdown/

smarttang commented 9 years ago

Can you give me your email? 在 Ya Zhuang notifications@github.com,2015年9月17日 上午12:04写道:maybe wrap all your code in code block ?

FYI: https://guides.github.com/features/mastering-markdown/

—Reply to this email directly or view it on GitHub.

jasonmoo commented 9 years ago

@smarttang I can't tell what the problem is here.

smarttang commented 9 years ago

Tomorrow i give you demo. Can you give me your email? i send modal for you. I m chinese .so, english is not good.sorry. 在 Jason Mooberry notifications@github.com,2015年9月17日 上午12:25写道:@smarttang I can't tell what the problem is here.

—Reply to this email directly or view it on GitHub.

zhuangya commented 9 years ago

@smarttang i can translate :)

zhuangya commented 9 years ago

Can you give me your email? 在 Ya Zhuang notifications@github.com,2015年9月17日 上午12:04写道:maybe wrap all your code in code block ?

FYI: https://guides.github.com/features/mastering-markdown/

—Reply to this email directly or view it on GitHub.

你就发这里呗。。我给你翻译就是了

smarttang commented 9 years ago

我想说得很简单的,就是当在td table里面,就没有法使用。 比如我的结构是for循环型的,用 /@spider 这样的没法用。

smarttang commented 9 years ago

这样的方式无法使用,特别是在modal里面,我用的是bootstrap v2 然后在modal弹窗下无法渲染。

  {{@spiders}}
       <td><div>{{=_val.url}} </div></td>
    {{/@spiders}}
smarttang commented 9 years ago

在modal视窗:

 <table class="table table-bordered table-striped">
    <thead>
      <tr><th width="60%">爬虫URL</th><th width="20%">爬取状态</th><th width="20%">页面状态</th></tr>
    </thead>
    <tbody>
    {{@spiders}}
       <Td><div>{{=_val.url}} </div></Td>
    {{/@spiders}}
    </tbody>
  </table>

javascript

function read_convent_task_report(task_id)
{
    var _dom=$('.convent-report').html();

    $.ajax({
        type: 'POST',
        url: CONVENT_REPORT_SOURCE,
        dataType: 'json',
        data: {'conventid':task_id},
        error: function(){
            console.log('read convent report error!');
        },
        success: function(msg){
            var template = new t(_dom);
            _readModal('查看报告',template.render(msg['data']),1);
        }
    });
}
smarttang commented 9 years ago

然后它就显示Uncaught TypeError: Cannot use 'in' operator to search for 'url' in undefined

smarttang commented 9 years ago

数据源(Data source)(JSON):

"spiders":[{"url":"http:\/\/my.37.com\/register.html","spider_status":"1","page_status":"1"},{"url":"http:\/\/my.37.com\/forgetpwd\/","spider_status":"2","page_status":"1"},{"url":"http:\/\/my.37.com\/user\/vip.php","spider_status":"2","page_status":"1"},{"url":"http:\/\/my.37.com\/user\/","spider_status":"2","page_status":"1"}]
zhuangya commented 9 years ago

目测 Uncaught TypeError: Cannot use 'in' operator to search for 'url' in undefined 是从 https://github.com/jasonmoo/t.js/blob/d21114e8148856756a9dda5a0fd0b5f28a7fc1b6/t.js#L74

报出来的,不然你看看 error stack 。

另外 你这个 $.ajax 回来的 msg 是什么?

看错误的话,应该是 msg['data']undefined


毕竟我用你这个模板,和你提供的这个数据,渲染出来是没问题的 参照 https://gist.github.com/zhuangya/fe1fc524c930d5ab8c49

不出意外的话应该就是你的 ajax 返回的结果和你期望的不一致。


@jasonmoo it should be a problem which is irrelevant to t.js

it's more like an ajax-response-unexpected-structure kind of thing

this issue should/could be closed after @smarttang confirms :)

smarttang commented 9 years ago

首先,AJAX返回的数据具体如下图所示: image 再看具体数据的结构: image 我相信应该是没有问题的,再看看代码。

function read_convent_task_report(task_id)
{
    var _dom=$('.convent-report').html();

    $.ajax({
        type: 'POST',
        url: CONVENT_REPORT_SOURCE,
        dataType: 'json',
        data: {'conventid':task_id},
        error: function(){
            console.log('read convent report error!');
        },
        success: function(msg){
            // 这个是modal bootstrap的渲染dom节点。
            var template = new t(_dom);
            // 这个是console输出的数据。
            // console.log(msg['data']);
            // 这个按照模板的说明是渲染。data就是具体的返回数据
            var html=template.render(msg['data']);
            // 渲染完直接弹出层
            _readModal('查看报告',html,1);
        }
    });
}

HTML具体的代码之前贴过,现在再贴一次,这个是待渲染的DOM节点。

<div class="form-work convent-report">
  <ol class="breadcrumb bread-work" style="background-color: #E8E8E8;">
      <li><a>扫描结果</a></li>
      <li class="active">任务信息</li>
  </ol>
   <div class="table-responsive">
    <div class="row">
      <div class="col-xs-12 col-md-7">
      <table class="table table-bordered table-striped">
        <thead>
          <tr><th width="20%">信息</th><th width="80%">内容</th></tr>
        </thead>
        <tbody>
          <tr><th scope="row"><code>任务名称</code></th><td>{{=title}}</td></tr>
          <tr><th scope="row"><code>扫描目标</code></th><td style="word-break:break-all; word-wrap:break-word;">{{@target}}<div class="label label-info">{{=_val}}</div><br />{{/@target}}</td></tr>
          <tr><th scope="row"><code>安全状态</code></th><td>{{=target_selevel}}</td></tr>
          <tr><th scope="row"><code>开始时间</code></th><td>{{=starttime}}</td></tr>
          <tr><th scope="row"><code>结束时间</code></th><td>{{=finishtime}}</td></tr>
          <tr><th scope="row"><code>总耗时</code></th><td>{{=consuming}}秒</td></tr>
          <tr><th scope="row"><code>检测模块数</code></th><td>{{=plugin_count}}</td></tr>
          <tr><th scope="row"><code>创建人</code></th><td>{{=create_user}}</td></tr>
        </tbody>
      </table>
      </div>
      <div class="col-xs-6 col-md-5">
        <div id="morris-donut-chart"><svg height="352" version="1.1" width="324" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="overflow: hidden; position: relative; left: -0.65625px;"><desc style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">Created with Raphaël 2.1.2</desc><defs style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></defs><path fill="none" stroke="#0b62a4" d="M162,279.8333333333333A101.33333333333333,101.33333333333333,0,0,0,257.7313560057369,211.72577195111194" stroke-width="2" opacity="0" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); opacity: 0;"></path><path fill="#0b62a4" stroke="#ffffff" d="M162,282.8333333333333A104.33333333333333,104.33333333333333,0,0,0,260.5655079927489,212.7094296733488L300.87344736358546,226.69922838960647A147,147,0,0,1,162,325.5Z" stroke-width="3" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path><path fill="none" stroke="#3980b5" d="M257.7313560057369,211.72577195111194A101.33333333333333,101.33333333333333,0,0,0,71.10315004168386,133.70929658846822" stroke-width="2" opacity="0" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); opacity: 0;"></path><path fill="#3980b5" stroke="#ffffff" d="M260.5655079927489,212.7094296733488A104.33333333333333,104.33333333333333,0,0,0,68.41212487844423,132.3832560269426L30.13976700125849,113.52401248524501A147,147,0,0,1,300.87344736358546,226.69922838960647Z" stroke-width="3" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path><path fill="none" stroke="#679dc6" d="M71.10315004168386,133.70929658846822A101.33333333333333,101.33333333333333,0,0,0,161.9681651949673,279.8333283327338" stroke-width="2" opacity="1" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); opacity: 1;"></path><path fill="#679dc6" stroke="#ffffff" d="M68.41212487844423,132.3832560269426A104.33333333333333,104.33333333333333,0,0,0,161.96722271718673,282.8333281846898L161.95224779245095,330.4999924991007A152,152,0,0,1,25.654725062525785,111.31394488270232Z" stroke-width="3" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path><text x="162" y="168.5" text-anchor="middle" font-family="&quot;Arial&quot;" font-size="15px" stroke="none" fill="#000000" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); text-anchor: middle; font-family: Arial; font-size: 15px; font-weight: 800;" font-weight="800" transform="matrix(1.5405,0,0,1.5405,-87.5544,-95.6613)" stroke-width="0.649157072368421"><tspan dy="5.5" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">Mail-Order Sales</tspan></text><text x="162" y="188.5" text-anchor="middle" font-family="&quot;Arial&quot;" font-size="14px" stroke="none" fill="#000000" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); text-anchor: middle; font-family: Arial; font-size: 14px;" transform="matrix(2.1111,0,0,2.1111,-180,-200.5556)" stroke-width="0.47368421052631576"><tspan dy="5" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">20</tspan></text></svg></div>
      </div>
    </div>
  </div>
  <ol class="breadcrumb bread-work" style="background-color: #E8E8E8;">
      <li><a>扫描结果</a></li>
      <li class="active">spider list</li>
  </ol>
  <table class="table table-bordered table-striped">
    <thead>
      <tr><th width="60%">爬虫URL</th><th width="20%">爬取状态</th><th width="20%">页面状态</th></tr>
    </thead>
    <tbody>
    {{@spiders}}
       <td>{{=_val.url}}</td>
    {{/@spiders}}
    </tbody>
  </table>

  <ol class="breadcrumb bread-work" style="background-color: #E8E8E8;">
      <li><a>扫描结果</a></li>
      <li class="active">风险细节</li>
  </ol>
  <ul id="myTab" class="nav nav-tabs">
   <li class="active"><a href="#" onclick="modal_tab('high');" data-toggle="tab">高危<span class="badge barge-vul">{{=vul_total.high}}</span></a></li>
   <li><a href="#" onclick="modal_tab('medium');" data-toggle="tab">中危<span class="badge barge-vul">{{=vul_total.medu}}</span></a></li>
   <li><a href="#" onclick="modal_tab('low');" data-toggle="tab">低危<span class="badge barge-vul">{{=vul_total.low}}</span></a></li>
  </ul>
  <div id="myTabContent" class="tab-content">
   <div class="tab-pane fade in active" id="high">
    <p class="biaoqian-modal">
      <ul class="media-list">
        <li class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" data-src="holder.js/64x64" alt="64x64" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+PCEtLQpTb3VyY2UgVVJMOiBob2xkZXIuanMvNjR4NjQKQ3JlYXRlZCB3aXRoIEhvbGRlci5qcyAyLjYuMC4KTGVhcm4gbW9yZSBhdCBodHRwOi8vaG9sZGVyanMuY29tCihjKSAyMDEyLTIwMTUgSXZhbiBNYWxvcGluc2t5IC0gaHR0cDovL2ltc2t5LmNvCi0tPjxkZWZzPjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+PCFbQ0RBVEFbI2hvbGRlcl8xNGY5M2NkYzNlOCB0ZXh0IHsgZmlsbDojQUFBQUFBO2ZvbnQtd2VpZ2h0OmJvbGQ7Zm9udC1mYW1pbHk6QXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7Zm9udC1zaXplOjEwcHQgfSBdXT48L3N0eWxlPjwvZGVmcz48ZyBpZD0iaG9sZGVyXzE0ZjkzY2RjM2U4Ij48cmVjdCB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSIxMy40NjA5Mzc1IiB5PSIzNi41Ij42NHg2NDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" data-holder-rendered="true" style="width: 64px; height: 64px;">
            </a>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Media heading</h4>
            <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.</p>
          </div>
        </li>
        <li class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" data-src="holder.js/64x64" alt="64x64" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+PCEtLQpTb3VyY2UgVVJMOiBob2xkZXIuanMvNjR4NjQKQ3JlYXRlZCB3aXRoIEhvbGRlci5qcyAyLjYuMC4KTGVhcm4gbW9yZSBhdCBodHRwOi8vaG9sZGVyanMuY29tCihjKSAyMDEyLTIwMTUgSXZhbiBNYWxvcGluc2t5IC0gaHR0cDovL2ltc2t5LmNvCi0tPjxkZWZzPjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+PCFbQ0RBVEFbI2hvbGRlcl8xNGY5M2NkYzNlOCB0ZXh0IHsgZmlsbDojQUFBQUFBO2ZvbnQtd2VpZ2h0OmJvbGQ7Zm9udC1mYW1pbHk6QXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7Zm9udC1zaXplOjEwcHQgfSBdXT48L3N0eWxlPjwvZGVmcz48ZyBpZD0iaG9sZGVyXzE0ZjkzY2RjM2U4Ij48cmVjdCB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSIxMy40NjA5Mzc1IiB5PSIzNi41Ij42NHg2NDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" data-holder-rendered="true" style="width: 64px; height: 64px;">
            </a>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Media heading</h4>
            <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.</p>
          </div>
        </li>
        <li class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" data-src="holder.js/64x64" alt="64x64" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+PCEtLQpTb3VyY2UgVVJMOiBob2xkZXIuanMvNjR4NjQKQ3JlYXRlZCB3aXRoIEhvbGRlci5qcyAyLjYuMC4KTGVhcm4gbW9yZSBhdCBodHRwOi8vaG9sZGVyanMuY29tCihjKSAyMDEyLTIwMTUgSXZhbiBNYWxvcGluc2t5IC0gaHR0cDovL2ltc2t5LmNvCi0tPjxkZWZzPjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+PCFbQ0RBVEFbI2hvbGRlcl8xNGY5M2NkYzNlOCB0ZXh0IHsgZmlsbDojQUFBQUFBO2ZvbnQtd2VpZ2h0OmJvbGQ7Zm9udC1mYW1pbHk6QXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7Zm9udC1zaXplOjEwcHQgfSBdXT48L3N0eWxlPjwvZGVmcz48ZyBpZD0iaG9sZGVyXzE0ZjkzY2RjM2U4Ij48cmVjdCB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSIxMy40NjA5Mzc1IiB5PSIzNi41Ij42NHg2NDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" data-holder-rendered="true" style="width: 64px; height: 64px;">
            </a>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Media heading</h4>
            <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.</p>
          </div>
        </li>
        <li class="media">
          <div class="media-left">
            <a href="#">
              <img class="media-object" data-src="holder.js/64x64" alt="64x64" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+PCEtLQpTb3VyY2UgVVJMOiBob2xkZXIuanMvNjR4NjQKQ3JlYXRlZCB3aXRoIEhvbGRlci5qcyAyLjYuMC4KTGVhcm4gbW9yZSBhdCBodHRwOi8vaG9sZGVyanMuY29tCihjKSAyMDEyLTIwMTUgSXZhbiBNYWxvcGluc2t5IC0gaHR0cDovL2ltc2t5LmNvCi0tPjxkZWZzPjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+PCFbQ0RBVEFbI2hvbGRlcl8xNGY5M2NkYzNlOCB0ZXh0IHsgZmlsbDojQUFBQUFBO2ZvbnQtd2VpZ2h0OmJvbGQ7Zm9udC1mYW1pbHk6QXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7Zm9udC1zaXplOjEwcHQgfSBdXT48L3N0eWxlPjwvZGVmcz48ZyBpZD0iaG9sZGVyXzE0ZjkzY2RjM2U4Ij48cmVjdCB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIGZpbGw9IiNFRUVFRUUiLz48Zz48dGV4dCB4PSIxMy40NjA5Mzc1IiB5PSIzNi41Ij42NHg2NDwvdGV4dD48L2c+PC9nPjwvc3ZnPg==" data-holder-rendered="true" style="width: 64px; height: 64px;">
            </a>
          </div>
          <div class="media-body">
            <h4 class="media-heading">Media heading</h4>
            <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.</p>
          </div>
        </li>
      </ul>
    </p>
   </div>
   <div class="tab-pane fade" id="medium">
    <p class="biaoqian-modal">Content of profile</p>
   </div>
   <div class="tab-pane fade" id="low">
    <p class="biaoqian-modal">Content of dropdown1</p>
   </div>
  </div>
  <div class="modal-footer">
    <button type='button' class='btn btn-default' data-dismiss='modal'>返回</button>
  </div>
</div>

具体WEB的效果如下: image

但是奇怪的是,如果将td的地方换掉,则正常的渲染。例如以下的方式: (改前)

  <ol class="breadcrumb bread-work" style="background-color: #E8E8E8;">
      <li><a>扫描结果</a></li>
      <li class="active">spider list</li>
  </ol>
  <table class="table table-bordered table-striped">
    <thead>
      <tr><th width="60%">爬虫URL</th><th width="20%">爬取状态</th><th width="20%">页面状态</th></tr>
    </thead>
    <tbody>
    {{@spiders}}
       <td>{{=_val.url}}</td>
    {{/@spiders}}
    </tbody>
  </table>

(改后)

  <ol class="breadcrumb bread-work" style="background-color: #E8E8E8;">
      <li><a>扫描结果</a></li>
      <li class="active">spider list</li>
  </ol>
  <table class="table table-bordered table-striped">
    <thead>
      <tr><th width="60%">爬虫URL</th><th width="20%">爬取状态</th><th width="20%">页面状态</th></tr>
    </thead>
    <tbody>
    {{@spiders}}
       {{=_val.url}}
    {{/@spiders}}
    </tbody>
  </table>

结果: image

这让我觉得特别崩溃。。。不能理解这是为什么。。。。

smarttang commented 9 years ago

关于modal的弹出,具体代码截图如下: image 我把它封装成一个方法。。。

zhuangya commented 9 years ago

msg['data'] 改成 msg !

smarttang commented 9 years ago

你估计没看明白,只要加了

<td></td>

就无法使用。 按照你所说的,再次尝试,结果更悲剧了。。连值都没有了。。 image image image

zhuangya commented 9 years ago
  1. https://gist.github.com/zhuangya/631ee0fd6e92a95eadcd 这个没有任何问题
  2. 是应该写 <tr><td> </td></tr> 吧。。
  3. 如果你这个请求,在 preview 里面显示的是截图那个样子,说明 content-type 错了。 $.ajax 里面加上 dataType: 'json' ref

毕竟,你对一个 stringspider 那么肯定是 undefined 的。。

smarttang commented 9 years ago

但是为啥不加html标签可以正常循环呢?而加了就不行?这个无法解释啊?

smarttang commented 9 years ago

https://gist.github.com/zhuangya/631ee0fd6e92a95eadcd 这个没有任何问题

这个无法访问。。。

zhuangya commented 9 years ago

it's about response content-type: the ajax response content-type is 'text/plain' rather than 'application/json'

not a problem about t.js

unsubscribing.

On Fri, Sep 18, 2015 at 3:27 PM, Tangyucong notifications@github.com wrote:

https://gist.github.com/zhuangya/631ee0fd6e92a95eadcd 这个没有任何问题

这个无法访问。。。

— Reply to this email directly or view it on GitHub https://github.com/jasonmoo/t.js/issues/13#issuecomment-141369601.

smarttang commented 9 years ago

image

我需要怎么解释?这个很明显返回就是json啊~。。。。

smarttang commented 9 years ago

image

好纠结。。。。

smarttang commented 9 years ago

或者我直接贴json源数据上来,你看怎么解析可以。。

{
    "status": 1,
    "data": {
        "target": [
            "http://my.37.com"
        ],
        "title": "测试DEMO",
        "create_user": "smart",
        "plugin_count": "2",
        "starttime": "2015-09-12 02:22:00",
        "finishtime": "2015-09-12 02:22:01",
        "consuming": 1,
        "vul_total": {
            "high": 0,
            "medu": 0,
            "low": 0
        },
        "level": "1",
        "timecurrt": 0,
        "target_selevel": "good",
        "spiders": [
            {
                "url": "http://my.37.com/register.html",
                "spider_status": "1",
                "page_status": "1"
            },
            {
                "url": "http://my.37.com/forgetpwd/",
                "spider_status": "2",
                "page_status": "1"
            },
            {
                "url": "http://my.37.com/user/vip.php",
                "spider_status": "2",
                "page_status": "1"
            },
            {
                "url": "http://my.37.com/user/",
                "spider_status": "2",
                "page_status": "1"
            }
        ],
        "loop": []
    }
}
smarttang commented 9 years ago

我知道为什么会这样了。。。 具体的解决办法很简单,将HTML的模板全部以字符串的方式拼凑,就可以解决这个问题。 如果是以DOM的方式来,会有问题。 image image

jasonmoo commented 9 years ago

Hey thanks for sorting this out guys. Was a little in the dark. Sounds like it came down to how the template was stored. Appreciate it @zhuangya.

smarttang commented 9 years ago

Enjoy the template.:)

zhuangya commented 9 years ago

Hey thanks for sorting this out guys. Was a little in the dark. Sounds like it came down to how the template was stored. Appreciate it @zhuangya.

no problem :)

我知道为什么会这样了。。。 具体的解决办法很简单,将HTML的模板全部以字符串的方式拼凑,就可以解决这个问题。 如果是以DOM的方式来,会有问题。

其实你可以把模板写在 <script type="text/template"> 里面的,用 innerHTML 取出来就好了。

smarttang commented 9 years ago

恩,但是对于我来说比较麻烦,我就没那么整了。。