修改table

This commit is contained in:
张博轩 2019-02-14 18:34:22 +08:00
parent 5a670b51d3
commit 7a4b3b9be4

View File

@ -67,7 +67,7 @@
<p class="table-title"> <p class="table-title">
<span class="btn btn-xs btn-info">请求参数</span> <span class="btn btn-xs btn-info">请求参数</span>
</p> </p>
<table id="methodRequird" class="table"> <table id="paramRequird" class="table">
<tr> <tr>
<td>参数</td> <td>参数</td>
<td>类型</td> <td>类型</td>
@ -77,6 +77,27 @@
</tr> </tr>
</table> </table>
</div> </div>
<div class="table-item col-md-12">
<p class="table-title">
<span class="btn btn-xs btn-info">返回参数</span>
</p>
<table id="returnRequird" class="table">
<tr>
<td>参数</td>
<td>类型</td>
<td>描述</td>
<td>默认值</td>
<td>是否必须</td>
</tr>
</table>
</div>
<div class="table-item col-md-12">
<p class="table-title">
<span class="btn btn-xs btn-info">状态码说明</span>
</p>
<table id="codeRequird" class="table">
</table>
</div>
</div> </div>
<div> <div>
</div> </div>
@ -128,15 +149,34 @@
editor.on('change', function (e) { editor.on('change', function (e) {
$('#params').val(editor.getValue()) $('#params').val(editor.getValue())
}) })
$(document).ready(function(){
intTable();
var valKey =$("#method option:first-child").text();
var data = <?php echo $data; ?>;
var methodArray = data[valKey];
changeTable(methodArray)
});
$('#method').bind('change', function() { $('#method').bind('change', function() {
var valKey = $("#method").find("option:selected").text(); var valKey = $("#method").find("option:selected").text();
var data = <?php echo $data; ?>; var data = <?php echo $data; ?>;
var methodArray = data[valKey]; var methodArray = data[valKey];
$("#methodRequird").empty(); intTable()
var html = "<tr><td>参数</td><td>类型</td><td>描述</td><td>默认值</td><td>是否必须</td></tr>"; changeTable(methodArray)
$(html).appendTo("#methodRequird"); })
console.log(methodArray, valKey) function intTable() {
methodArray.map(function (val, index) { $("#paramRequird").empty();
$("#returnRequird").empty();
$("#codeRequird").empty();
var html1 = "<tr><td>参数</td><td>类型</td><td>描述</td><td>默认值</td><td>是否必须</td></tr>";
var html2 = "<tr><td>参数</td><td>类型</td><td>描述</td>/tr>";
var html3 = "<tr><td>状态码</td><td>描述</td></tr>";
$(html1).appendTo("#paramRequird");
$(html2).appendTo("#returnRequird");
$(html3).appendTo("#codeRequird");
}
function changeTable(params) {
params.param.map(function (val, index) {
var $trTemp = $("<tr></tr>"); var $trTemp = $("<tr></tr>");
//往行里面追加 td单元格 //往行里面追加 td单元格
$trTemp.append("<td>"+ data[i].param_name +"</td>"); $trTemp.append("<td>"+ data[i].param_name +"</td>");
@ -146,7 +186,22 @@
$trTemp.append("<td>"+ data[i].param_require +"</td>"); $trTemp.append("<td>"+ data[i].param_require +"</td>");
$trTemp.appendTo("#methodRequird"); $trTemp.appendTo("#methodRequird");
}) })
params.return.map(function (val, index) {
var $trTemp = $("<tr></tr>");
//往行里面追加 td单元格
$trTemp.append("<td>"+ data[i].return_name +"</td>");
$trTemp.append("<td>"+ data[i].return_type +"</td>");
$trTemp.append("<td>"+ data[i].return_title +"</td>");
$trTemp.appendTo("#methodRequird");
}) })
params.code.map(function (val, index) {
var $trTemp = $("<tr></tr>");
//往行里面追加 td单元格
$trTemp.append("<td>"+ data[i].code +"</td>");
$trTemp.append("<td>"+ data[i].content +"</td>");
$trTemp.appendTo("#methodRequird");
})
}
</script> </script>
<script>hljs.initHighlightingOnLoad();</script> <script>hljs.initHighlightingOnLoad();</script>
</body> </body>