I have a tabset that is rendering article records. Does someone have a lightning example how I would create the index to set the tab title and the order?
HTML
<template>
<lightning-card title="ApexWireMethodToProperty">
<lightning-tabset variant="scoped">
<template for:each={articles.data} for:item="article" for:index="index">
<lightning-tab label={article.Title} key={article.Id}>
<lightning-record-form key={article.Id} record-id={article.Id} object-api-name="Knowledge__kav"
layout-type="Full" mode="view">
</lightning-record-form>
</lightning-tab></template></lightning-tabset>
</lightning-card>
JS
[import { LightningElement, api, track, wire } from 'lwc';
import fetchArticles from '@salesforce/apex/SampleAuraController.fetchArticles';
//import {getRecord} from 'lightning/uiRecordApi';
export default class ArticleList extends LightningElement {
@track articleList;
@api articleList = \[ { title: "Group 1 article" , index : 1} ,
{ title: "How to Clean and Maintain Your Solar Panel" , index : 2} ,
{ title: "Menu 2 articles" , index :3} ,
{title: "Group 1 article 2", index :4}\];
@api recordId;
@api objectApiName;
@wire(fetchArticles) wiredArticles({data,error}){
if(data){
this.articleList=data;
this.articleList = \["Group 1 article", "Group 1 article 2", "Menu 2 articles","How to Clean and Maintain Your Solar Panel"\];//controls order or articles
this.articleList = this.articleList.map((title, index) => {
return { title, sno: index + 1 };
});
console.log(data);
} else if (error) {
console.log(error);
} }}
Apex class
public class SampleAuraController {
@AuraEnabled(cacheable=true)
public static List < Knowledge__kav > fetchArticles() {
return
// [SELECT Id, Title,ArticleNumber,Article_body__c,PublishStatus FROM Knowledge__kav where Title=:Title and PublishStatus='Online'];
[SELECT Id, Title,ArticleNumber,Article_body__c,PublishStatus FROM Knowledge__kav where PublishStatus='Online'];
}
}