Javascript:变量在分配时被修剪

时间:2015-10-19 20:15:55

标签: javascript ajax

我有一个从AJAX返回的变量row['case'],它等于" Hello World!"。问题是,当我尝试将其分配给另一个变量时,只有" Hello"正在分配row['case'] = "Hello",而不是row['case'] = "Hello World!"

以下是存在问题的代码块:

$(document).ready(function() {
  var table = $('#peacecard').DataTable({
    "ajax": "http://localhost:8080/peace_reports/data.php",
    "columns": [
      {
        "className":      'details-control',
        "orderable":      false,
        "data":           null,
        "defaultContent": ''
      },
      { "data": "Name" },
      { "data": "Vendor", "className": 'dt-right' }
      { "data": "case", "render": function(data, type, row, meta){
                                    if (data == "true"){ 
                                      data = "<i title="+row['case2']+" id='thei'; } 
                                    else { data = ""; }
                                    return data; }, 
                                    "className": 'dt-center'}
    ],
    "order": [[1, 'asc']]
  });

这是console.log(行)显示的内容:

Object {Vendor: "123", Name: "MyHome", case2: "Hello World!"}

1 个答案:

答案 0 :(得分:1)

您在此行中缺少引号和</i>

data = "<i title="+row['case2']+" id='thei';

应该是这样的:

data = "<i title='"+row['case2']+"' id='thei'></i>";