首页 文章

jQuery DataTables:未捕获的TypeError:无法读取未定义的属性'mData'

提问于
浏览
3

为什么我收到错误

未捕获的TypeError:无法读取未定义的属性'mData'

我尊重DataTables的要求(我还阅读了有关我的错误的其他主题,我尊重每个答案和解决方案) . 请帮我 .

这是我的PHP代码:

<table class="table table-striped table-bordered table-hover" id="sample_1">
        <thead>
            <tr>
                <th class="table-checkbox">
                    <input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
                </th>
                <th>
                     Utilizator
                </th>
                <th>
                     Nume complet
                </th>
                <th>
                     Clasa
                </th>
                <th>
                     Functia
                </th>
                <th>
                     E-Mail
                </th>
                <th>
                     Ultima logare
                </th>
            </tr>
        </thead>
        <tbody>
            <?
               foreach($data["users"] as $student)
               {
            ?>
            <tr class="odd gradeX">
                <td>
                    <input type="checkbox" class="checkboxes" value="1"/>
                </td>
                <td>
                     <? echo $student["username"]; ?>
                </td>
                <td>
                     <? echo " ".$student["last_name"]." ".$student["first_name"].""; ?>
                </td>
                <td>
                     <? echo getclass($student["class"]); ?>
                </td>
                <td>
                     <?
                     $functie = 0;
                     if($student["role"] == 1)
                     {
                         $functie = 1;
                         echo "Administrator site";
                     }
                     if($student["fctsc"])
                     {
                         $functie = 1;
                         echo "Director";
                     }
                     if($student["diriginte"])
                     {
                         $functie = 1;
                         echo "Diriginte";
                     }
                     if($student["profesor"])
                     {
                         $functie = 1;
                         echo "Profesor";
                     }
                     if($functie == 0)
                         echo "Elev";
                     ?>
                </td>
                <td>
                    <a href="mailto:<? echo $student["email"]; ?>">
                        <? echo $student["email"]; ?>
                    </a>
                </td>
                <td class="center">
                     <? echo $student["lastlogin"]; ?>
                </td>
            </tr>
            <?
               }
            ?>
        </tbody>
    </table>

2 回答

  • 0

    在所有行上检查天气或不是所有的php echo 's are actually outputting something that is not ' NULL',因为DataTables会将任何只有NULL作为内容的单元格视为非existant,这也可能导致该错误 .
    尝试避免直接php输出到html表 .

  • 0

    通常出现此错误有两个原因:

    • 缺少表头 .

    • 表格主体中 td 元素的数量与表格 Headers 中的 th 元素数量不同 .

    但是,您的HTML代码似乎具有正确的列数,请参阅this example .

    有关更多信息,请参阅jQuery DataTables: Common JavaScript console errors - TypeError: Cannot read property ‘mData’ of undefined .

相关问题