Skip to main content
deleted 36 characters in body; edited tags
Source Link
Ganesh Sanap - MVP
  • 46.4k
  • 22
  • 31
  • 63

ImI'm trying to create a React SPFx web part which can render items from a SPO list.

I am having difficulty if the column is a HyperLinkHyperlink.    (I can get the value if it is a string).

Does anyone know how to render the value if it's a hyperlink?

Thanks P

public render(): React.ReactElement {

public render(): React.ReactElement<ISplistitemsdataProps> {  

  const onRenderItemColumn = (item: ISplistitemsState, index: number, column: IColumn) => {

  const fieldContent = item[column.fieldName as keyof ISplistitemsState] as any;
  let typeOfThisObject: string = (typeof fieldContent).toString();
  let valueToReturn: string = "";

  if(typeOfThisObject == "object")
  {

    try {
      valueToReturn = fieldContent.toString();
      valueToReturn = 

      const values = Object.keys(fieldContent).map(key => fieldContent[key]);
      //valueToReturn = "<a href='" + values[1] + "'>" + values[0] + "</a>";
      //valueToReturn = "object:" + values[1] + "-" + values[0];

      const values2 = Object.keys(values[0]).map(key => values[0][key]);
      //valueToReturn += "object2:" + values2[1] + "-" + values2[0];

} catch (e)          
        {
          valueToReturn = e.message.toString();
        }

      } else {
        valueToReturn = "not object:" + fieldContent;
      }

Im trying to create a React SPFx web part which can render items from a SPO list.

I am having difficulty if the column is a HyperLink.  (I can get the value if it is a string).

Does anyone know how to render the value if it's a hyperlink?

Thanks P

public render(): React.ReactElement {

const onRenderItemColumn = (item: ISplistitemsState, index: number, column: IColumn) => {

  const fieldContent = item[column.fieldName as keyof ISplistitemsState] as any;
  let typeOfThisObject: string = (typeof fieldContent).toString();
  let valueToReturn: string = "";

  if(typeOfThisObject == "object")
  {

    try{
      valueToReturn = fieldContent.toString();
      valueToReturn = 

      const values = Object.keys(fieldContent).map(key => fieldContent[key]);
      //valueToReturn = "<a href='" + values[1] + "'>" + values[0] + "</a>";
      //valueToReturn = "object:" + values[1] + "-" + values[0];

      const values2 = Object.keys(values[0]).map(key => values[0][key]);
      //valueToReturn += "object2:" + values2[1] + "-" + values2[0];

}catch (e)          
        {
          valueToReturn = e.message.toString();
        }

      }else{
        valueToReturn = "not object:" + fieldContent;
      }

I'm trying to create a React SPFx web part which can render items from a SPO list.

I am having difficulty if the column is a Hyperlink.  (I can get the value if it is a string).

Does anyone know how to render the value if it's a hyperlink?

public render(): React.ReactElement<ISplistitemsdataProps> {  

  const onRenderItemColumn = (item: ISplistitemsState, index: number, column: IColumn) => {

  const fieldContent = item[column.fieldName as keyof ISplistitemsState] as any;
  let typeOfThisObject: string = (typeof fieldContent).toString();
  let valueToReturn: string = "";

  if(typeOfThisObject == "object") {

    try {
      valueToReturn = fieldContent.toString();
      valueToReturn = 

      const values = Object.keys(fieldContent).map(key => fieldContent[key]);
      //valueToReturn = "<a href='" + values[1] + "'>" + values[0] + "</a>";
      //valueToReturn = "object:" + values[1] + "-" + values[0];

      const values2 = Object.keys(values[0]).map(key => values[0][key]);
      //valueToReturn += "object2:" + values2[1] + "-" + values2[0];

} catch (e) {
          valueToReturn = e.message.toString();
        }

      } else {
        valueToReturn = "not object:" + fieldContent;
      }
Source Link
Pete Whelan
  • 109
  • 1
  • 4
  • 17

SPFx - How to get the URL and description from a hyperlink?

Im trying to create a React SPFx web part which can render items from a SPO list.

I am having difficulty if the column is a HyperLink. (I can get the value if it is a string).

Does anyone know how to render the value if it's a hyperlink?

Thanks P

public render(): React.ReactElement {

const onRenderItemColumn = (item: ISplistitemsState, index: number, column: IColumn) => {

  const fieldContent = item[column.fieldName as keyof ISplistitemsState] as any;
  let typeOfThisObject: string = (typeof fieldContent).toString();
  let valueToReturn: string = "";

  if(typeOfThisObject == "object")
  {

    try{
      valueToReturn = fieldContent.toString();
      valueToReturn = 

      const values = Object.keys(fieldContent).map(key => fieldContent[key]);
      //valueToReturn = "<a href='" + values[1] + "'>" + values[0] + "</a>";
      //valueToReturn = "object:" + values[1] + "-" + values[0];

      const values2 = Object.keys(values[0]).map(key => values[0][key]);
      //valueToReturn += "object2:" + values2[1] + "-" + values2[0];

}catch (e)          
        {
          valueToReturn = e.message.toString();
        }

      }else{
        valueToReturn = "not object:" + fieldContent;
      }