列和行是向后JSON

时间:2017-04-05 09:18:08

标签: javascript html json html-table

我在index.html中有以下代码,用于获取字典列表和 将键和值打印到表中

$(function() {
      $('a#search').bind('click', function() {
        $.getJSON('/_search', {
          a: $('input[name="a"]').val()
        }, function(data) {
          var tableData = '<table>'
          $.each(data.result, function(key, value){
            tableData += '<tr>' + '   ' + key + '   ' + '</tr>';
            alert(key)
            $.each(value, function(val){
                alert(value[val])
                tableData += '<td>' + value[val] + '</td>';
              });
          });
          tableData += '</table>';
          $('#table').html(tableData);
        });
        return false;
      });
    });

但是我的输出如下

Developer Publisher ReleaseDate Title
Office    Koukan    Jorudan Beam Software
Shouei    VAP       Hi Tech Expressions
March 18, 1994  November 18, 1994   October 1, 1993
Idea no Hi  Pachinko Hi Hisshouhou  hunThe Hunt for Red October

当输出应为

   Developer      Publisher ReleaseDate Title
   Office Kouan   Shouei    ...         ...
   Jorudan        VAP       ...         ...
   Beam Software  ...       ...         ...

知道我可能做错了吗?

1 个答案:

答案 0 :(得分:0)

您正在关闭import React from 'react'; import ReactDOM from 'react-dom'; import EmpLogin from './EmpLogin'; import {Router, Route,HashRouter} from 'react-router-dom'; import {browserHistory,hashHistory} from 'react-router'; import EmpDetails from './EmpDetails'; ReactDOM.render(( <HashRouter> <div> <Route exact path='/' component={EmpLogin}/> <Route path='/Emplogin' component={EmpLogin}/> <Route path='/EmpDetails' component={EmpDetails} /> </div> </HashRouter> ), document.getElementById('root')); 标记,而不是在向其添加所有<tr>之后。尝试类似:

<td>

如果表格不是您想要的输出,请发布JSON样本,如果您可以控制此结构。