2013-01-09 33 views
2

我從數據庫中獲取數據,但其中一個是像這樣的'〜\ images \ food.png'的圖像文件路徑,但我想,但它在一個img標籤,所以它可以顯示圖像不是路徑。有人幫忙,請提前致謝。jquery datatables img在aoCoulumn

 $(document).ready(function() { 
    load(); 
}); 
function load() { 
    $.ajax({ 
     type: "POST", 
     url: "ParentCategoryManagment.aspx/PopulateCategories", 
     contentType: "application/json; charset=utf-8", 
     data: "{}", 
     dataType: "json", 
     success: AjaxSucceeded, 
     error: AjaxFailed 
    }); 
} 
function AjaxSucceeded(respone) { 

    var json = jQuery.parseJSON(respone.d); 

    if (typeof oTable == 'undefined') { 
     oTable = $('#tblData').dataTable({ 
      'aaData': json, 
      'aoColumns': 
       [ 
        { "mDataProp": "Id" }, 
        { "mDataProp": "Name" }, 
        { "mDataProp": "ImagePath" }, 
        { "mDataProp": null, "sDefaultContent": '<a class="edit" href="">Edit</a>' }, 
        { "mDataProp": null, "sDefaultContent": '<a class="delete" href="">Delete</a>' } 
       ] 
     }); 
    } 
    else { 

     oTable.fnClearTable(0); 
     oTable.fnAddData(json); 
     oTable.fnDraw(); 

    } 
} 
function AjaxFailed(result) { 
    alert('Ajax Failed'); 
} 
+0

你好需要的信息你可以聊天嗎? http://chat.stackoverflow.com/rooms/22475/chattable – sajawikio

+0

我不明白你的問題。添加更多信息。 – sdespont

+0

sajawikio我不能聊天,因爲我需要20代表 – Thinker

回答

2

見的jsfiddle DEMOhttp://jsfiddle.net/HPdVH/5/

你需要通過每個圖像路徑,並將其變成圖像。在你的情況下,它似乎總是第三個表格列,所以你可以在你的表格通過ajax加載後做到這一點:

$("tr").each(function(){ 
     $(this).children("td") 
       .eq(2) 
       .html("<img src='" + $(this).html() + "'/>"); 
}) 
+0

哇謝謝它的工作,但它只適用於第一行XD – Thinker

+0

更好的想法可能是這樣的:修改json對象在哪裏它說使用javascript添加圖像標記的Imagepath在填充表之前,然後用json – sajawikio

+0

$(「tr」)。each(function(){this).children(「td」)填充表格。 .eq(2).each(function(){ var k = $(this).html(); $(this).html(「」); }); }); – Thinker