【问题标题】:Cannot read property 'mData' of undefined in Salesforce无法读取 Salesforce 中未定义的属性“mData”
【发布时间】:2015-10-01 07:14:23
【问题描述】:

我正在尝试从列表中获取数据并使用 jQuery 对其进行排序,但为此我在控制台上收到此错误。

无法读取控制台上未定义的属性“mData”。

如果我添加静态数据,它就可以工作。我是 jQuery 新手。

VF 页面

<apex:page sidebar="false" controller="PaginationCon">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>

  <link href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet"/>

 <script type="text/javascript">

             $(function () {
            $("#example1").dataTable();            
        });          

    </script>

  <apex:form >
       <table id="example1" class="table table-bordered table-striped">

        <thead>
            <tr>
                <th>Name</th>
                <th>BodyLength</th>
                <th>Created Date</th>
                <th>Owner Name</th>
                <th>Click To View</th>
            </tr>

        </thead>

        <tbody>
           <apex:repeat value="{!att}" var="at">
<tr>
    <td> <apex:outputText value="{!at.Name}"/></td>
    <td> <apex:outputText value="{!at.BodyLength}"/></td>
    <td> <apex:outputText value="{!at.CreatedDate}"/></td>
    <td> <apex:outputText value="{!at.Owner.Name}"/></td>
    <td> <apex:commandLink value="View"/></td>
    <td> <apex:commandLink value="Delete"/></td>      
</tr>
  </apex:repeat>
 </tbody>

    </table>

  </apex:form>
</apex:page>

控制器

public with sharing class PaginationCon {

    public List<Attachment> att{get;set;}

    public PaginationCon ()
    {
        att=new List<Attachment>();
        att=[select id,Name,BodyLength,CreatedDate,Owner.Name from Attachment limit 1000];
    }
}

【问题讨论】:

  • 我认为 datatable() 在 tbody 和 thead 中需要相同数量的列。您在标题中有 5 列,在正文中有 6 列...请在删除“删除 td”后测试 --- 或在广告部分添加另一个 td

标签: jquery salesforce visualforce


【解决方案1】:

只需在“点击查看”表头下方添加此元素

<th>Click To Delete</th>

现在应该是这个了。

<thead>
<tr>
    <th>Name</th>
    <th>BodyLength</th>
    <th>Created Date</th>
    <th>Owner Name</th>
    <th>Click To View</th>
    <th>Click To Delete</th>
</tr>
</thead>

&lt;thead&gt;&lt;tbody&gt; 的列数应该相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 2015-07-19
    相关资源
    最近更新 更多