У меня есть молния: datatable, которая мне нужна для загрузки данных, когда пользователь прокручивает.Я обнаружил, что событие onloadmore вызывается, когда пользователь нажимает на строку таблицы, а не когда пользователь прокручивает таблицу.
Более того, как только запускается onloadmore, он продолжает вызывать до загрузки всех записей вбазы данных.
Может кто-нибудь помочь мне понять, почему это делает и обходной путь?Любая помощь будет принята с благодарностью.
Чтобы проверить, как вызывается функция loadMoreData, откройте инспектор и проверьте консоль после нажатия на строку.
Вот пример:
testDataTable.cmp
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="ContactController">
<aura:attribute name="data" type="Object"/>
<aura:attribute name="columns" type="List"/>
<aura:attribute name="rowsToLoad" type="Integer" default="10"/>
<aura:attribute name="enableInfiniteLoading" type="Boolean" default="false"/>
<aura:attribute name="loadMoreOffset" type="Integer" default="5"/>
<aura:attribute name="loadMoreStatus" type="String" default=""/>
<!-- handlers-->
<aura:handler name="init" value="{! this }" action="{! c.doInit }"/>
<lightning:card title="testDataTableCard">
<lightning:datatable
keyField="Id"
data="{! v.data }"
columns="{! v.columns }"
enableInfiniteLoading="{! v.enableInfiniteLoading }"
onloadmore="{! c.loadMoreData }"/>
</lightning:card>
</aura:component>
testDataTableController.js
({
doInit : function(component, event, helper) {
component.set('v.columns', [
{label: 'Id', fieldName: 'Id', type: 'text'},
{label: 'LastName', fieldName: 'LastName', type: 'text'}
]);
helper.loadContacts(component, event, helper);
},
loadMoreData: function(component, event, helper) {
console.log('loadMoreData called');
}
})
testDataTableHelper.js
({
loadContacts : function(component, event, helper) {
var action = component.get("c.getContacts");
action.setStorable();
action.setCallback(this,function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var records = response.getReturnValue();
component.set("v.data", records);
component.set("v.enableInfiniteLoading", true);
} else {
console.log('ERROR');
}
});
$A.enqueueAction(action);
}
})
ContactController.class
public class ContactController {
@AuraEnabled
public static List<Contact> getContacts() {
return[Select Id, LastName From Contact Limit 10];
}
}
Библиотека компонентов молнии: молния: бесконечная загрузка данных