Hi Team,
I have followed a youtube vedio (part 2 as well) to get sp list items in to SPFX webpart, which is working fine, in the same way i have tried to get SP Site contens (Get SP lists) list, which is getting blank values.
Here is the webpart.TS file
public render(): void {
const element: React.ReactElement = React.createElement(
GetSpLists,
{
description: this.properties.description,
websiteUrl: this.context.pageContext.web.absoluteUrl //here i am getting the site URL which is working fine
}
);
ReactDom.render(element, this.domElement);
}
After that Framework Interface file
export interface IGetSpListsProps {
description: string;
websiteUrl: string; //React FrameWork interface file initialized for Site URL
}
Now TSX file from Component
export interface IGetSpListsState{
sitecontents: [{"Lists":""}]
}
export default class GetSpLists extends React.Component {
static siteurl:string =""; //static member variable
public constructor (props :IGetSpListsProps, state:IGetSpListsState ){
super(props);
this.state={sitecontents: [{"Lists":""}]};
GetSpLists.siteurl=this.props.websiteUrl;
}
public componentDidMount() {
let reactcontexthandiler= this;
jquery.ajax({
url: `${GetSpLists.siteurl}/_api/web/lists?select=Title&$filter=Hidden eq true`,
type:"GET",
headers:{'Accept': 'application/json;odata=verbose;'},
success : function (resultData){
reactcontexthandiler.setState({sitecontents: resultData.d.results});
},
error: function (jqXHR, textStatus, errorthrown){
}
});
}
public render(): React.ReactElement {
return (
{
this.state.sitecontents.map(function(mylists,mylistitemkey){
return(
-
{mylists.Lists}
);
})
}
);
}
}
Every thing is fine but i am getting blank values from SP. please check the below screen shot for output that i am getting.

Please assist me what is the issue and why its not displaying.
Deepak RawatPosted Jul 17, 2023, 10:17 AM
Based on the provided code and screenshot, there could be a couple of reasons why you're getting blank values for the SP Site Contents (Get SP lists) list:
Filter condition: In the URL for retrieving lists, you have specified the filter condition
Hidden eq true. This filter will only return hidden lists. If you want to retrieve all lists, including visible ones, you should remove the$filterparameter from the URL or modify the filter condition accordingly.Incorrect property mapping: In the
renderfunction, you are trying to access theListsproperty of each list item in the state (mylists.Lists). However, based on the screenshot, it seems like the correct property to access the list title should beTitle. Modify the code as follows:Make sure to change
mylists.Liststomylists.Titlein thespanelement.