如何在闪电组件中使用jQuery插件(数据表) - Salesforce?

时间:2016-06-20 06:02:29

标签: jquery datatables salesforce

我无法调用jQuery数据表函数。以下是详细信息 -

DatatableApp.app -

<aura:application >
        <c:DatatableComponent />
</aura:application>

DatatableComponent.cmp -

<aura:component controller="DatatableController">
<!-- Static Resource details - jQuery js file --> (jQUerySource), jQuery Datatable file --> (jqueryDatatableJS) -->
    <ltng:require scripts="/resource/1466061468000/jQuerySource,/resource/1466061531000/jqueryDatatableJS" afterScriptsLoaded="{!c.jsLoaded}"/>
<!-- doInit method will call JS controller and then will get the details from Apex Controller and put in into the HTML using aura:iteration -->
  <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> 
              <table class="display" id="#sampleTable">
            <thead>
                <tr>
                    <th>ID</th>
                </tr>
            </thead>
            <tbody>
                  <aura:iteration items="{!v.cases}" var="case">
         <tr><td>1</td><td>{!case.Id}</td></tr>
       </aura:iteration>
            </tbody>
        </table>
        </div>
        <div class="col-md-2"></div>
    </div>
 </aura:component>

DatatableComponentController.js -

({
    jsLoaded: function(component, event, helper) {
        debugger;
        $('#sampleTable').DataTable();
    },
   doInit: function(component, event, helper) {    
      helper.getCaseList(component);   
   }
})

DatatableComponentHelper.js -

({
    getCaseList: function(component) {
    var action = component.get("c.getCases");
    var self = this;
    action.setCallback(this, function(actionResult) {
        component.set("v.cases", actionResult.getReturnValue());            
    });
    $A.enqueueAction(action);
  }   
})

DatatableController.apxc -

public class DatatableController {
       @AuraEnabled
       public static List<Case> getCases() {
           system.debug([SELECT Id FROM Case limit 10]);
           return [SELECT Id FROM Case limit 10];
       }   
    }

点击预览按钮。我收到了这个错误 -

Option is not a constructor

我在这里使用jQuery数据表(https://datatables.net/)。

0 个答案:

没有答案