fnCallback在数据表中仅显示响应的第一个字母

时间:2019-01-03 11:36:30

标签: elasticsearch datatable datatables

我正在从ElasticSearch索引中获取数据表数据,如下所示。当我想将数据呈现到数据表中时,仅填充fnCallback方法中result的第一个字母。我在这里想念什么吗?

var oTable = $('#titleTable').dataTable( {
        "bProcessing": true,
        "sDom" : '<"top"i>rt>',
        "bSort": false,
        "asStripeClasses": [],
        "sAjaxSource": "http://localhost:9200/data_index/_search?source_content_type=application/json&source={\"query\":{\"match_all\":{}}}}",
        "fnServerParams": function ( aoData ) {
            aoData.push(
                { "name": "title_search", "value":  $('#title_search').val()}
            );

        },
        "fnServerData": function (sSource, aoData, fnCallback){
            var sEcho=aoData[0].value;
            query = '{"query":{"match_all":{}}}';
            $.ajax({
                "type": "GET",
                "url": sSource,
                "success": function(response) {
                    var result = new Object();
                    result["sEcho"] = sEcho;
                    result["iTotalRecords"] = response.hits.total;
                    result["iTotalDisplayRecords"] = response.hits.total;

                    var arr = ["<table style=\"width: 100%;\"><tbody><tr>"];
	            response['hits']['hits'].map(function(i){

                         arr.push("<td><table><tr><td><div class=\"title\">" +
							"<a href=\"report.php?a=CompanyDetail&id=853\">" +
							"<img src=\"images/company/12345.jpg\"><br />"+i['_source']['company_title']+
							"</a></div></td></tr><tr><td><div class=\"bookmark-title\" onclick=\"return edit_company(853);\">" +
							"<span id=\"editcompany_853\">Edit Company</span></div></td></tr></table></td>");


                    });
                    arr.push("</tr></tbody></table>");
					
                    result["aaData"] = arr;
                    fnCallback(result);
                },
                error: function (xhr, textStatus, error){
                }
            });
        }
    });

结果JSON

{  
   "sEcho":1,
   "iTotalRecords":11,
   "iTotalDisplayRecords":11,
   "aaData":[  
      "<table style=\"width: 100%;\"><tbody><tr>",
      "<td><table><tr><td><div class=\"title\"><a href=\"assetMngt.php?a=Details&id=853\"> 
<img src=\"images/titles/1234567.jpg\"><br />TTC Developers</a></div></td></tr><tr><td><div class=\"edit-company\" onclick=\"return edit-company(853);\"><span id=\"editcompany_853\">Edit Company</span></div></td></tr></table>"
   ]
}

0 个答案:

没有答案