0

I have got problem with response . json() return problem. I have got two methods one is Mocking List, and another is by JSON. Mock method works superb. but return from response.json() returned me undefined values.

The records are the same like in list - 4, but for all columns it returned undefined.

Here is my code:

private _getMockListData(): Promise<ISPLists> {
    return MockHttpList.get(this.context.pageContext.web.absoluteUrl).then(() => {
            const listData: ISPLists = {
                value:
                [
                    { Tytuł1: 'WP', Link1: 'www.wp.pl', Link_zdjecie1: 'https://d.wpimg.pl/10002867-366860448/392x330.png'},
                    { Tytuł1: 'Onet', Link1: 'www.onet.pl', Link_zdjecie1: 'https://upload.wikimedia.org/wikipedia/commons/b/b7/Onet_pl.png'},
                    { Tytuł1: 'Interia', Link1: 'www.interia.pl', Link_zdjecie1: 'https://upload.wikimedia.org/wikipedia/commons/b/b7/Onet_pl.png'}
                ]
            };
            return listData;
        }
    ) as Promise<ISPLists>;
}

private async _getListData(): Promise<ISPLists> {
    return this.context.spHttpClient.get('https://sharepointTenant/sites/SharepointSite/_api/web/lists/GetByTitle(\'Wlasciwosci_toolbox\')/Items', SPHttpClient.configurations.v1)
    .then((response: SPHttpClientResponse) => {
        return response.json();
    });
}

Please help me. Here is two code errors:

enter image description here

enter image description here

0

Try using below code:

private _getListData(): Promise<ISPLists> {  
    return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/lists/GetByTitle('Display Name of List')/Items`, SPHttpClient.configurations.v1)  
        .then((response: SPHttpClientResponse) => {   
            debugger;  
            return response.json();  
    });  
}

Replace Display Name of List in code with the Display name of your list.

  • Still undefinied: undefined – Grzegorz Z Sep 10 at 9:22
  • 1
    At which line are you getting error? Can you please check the error line in console? – Ganesh Sanap Sep 10 at 9:23
  • I have got only TypeError: this is undefined in console – Grzegorz Z Sep 10 at 9:26
  • 1
    Yes, But at which line number in your code you are getting this error? Can you please add any screenshot an error you are getting? – Ganesh Sanap Sep 10 at 9:39
  • I added 2 screenshots. and I getting too this error too: Key hoverTargetStrings.ariaLabelWithPersonInfo does not exist in string map – Grzegorz Z Sep 10 at 9:48
0

I did sample test project and shared in github, hope this would help you.

this.props.context.spHttpClient.get(`${this.props.context.pageContext.web.absoluteUrl}/_api/web/lists/getbytitle('TestList')/items?select=ID,Title,Address`,
    SPHttpClient.configurations.v1) .then((response: SPHttpClientResponse) => {  
      response.json().then((responseJSON: any) => {            
        reactHandler.setState({
          items: responseJSON.value
        });
      });  
    }); 

https://github.com/OS-Lee/ReactSPFx/blob/master/src/webparts/reactSpFx/components/ReactSpFx.tsx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.