html页面访问后台数据访问不到

<% for(var i = 0; i < dataList.length; i++) { %>


  <tbody>

    <tr data-id="<%=dataList[i].attributes.id%>">

          <th scope="row">

              <input type="checkbox" id="<%=dataList[i].attributes['id']%>">

          </th>

          <td><%=dataList[i].attributes["local"]%></td>

          <td></td>

    </tr>

  </tbody>

<% } %>




报错:Uncaught TypeError: Cannot read property 'id' of undefined

at eval (eval at _.template (underscore.js:1442), <anonymous>:8:31)

at template (underscore.js:1449)

at s.initSetup (setupTopoManage.replaceNode.view.js?1510834444737:31)

at s.onClickSearchOriginNode 


噜噜哒
浏览 565回答 1
1回答

ITMISS

数据请求不到,接口返回是啥?dataList打印一下嘛,看看里面具体是啥我underscore不太熟你试试这样行不行。var templateTable2 = '<% _.each(dataList, function(n){ %>\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tbody><tr data-id="<%=n.id %>">\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th scope="row">\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="checkbox" id="<%=n.id %>"</th>\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><%=n.local %></td>\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><%=n.upper %></td>\&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr></tbody><% });%>';&nbsp;var data= [{ id: 101,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local:'联通',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; upper:'北京教育网'&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: 102,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local:'电信',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; upper:'北京教育网'&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}];&nbsp;var tpl = _.template(templateTable2)({ dataList:data });&nbsp;console.log(tpl);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript