首页 > 解决方案 > 如何从 Sharepoint Online 中的查找列中检索文本?

问题描述

下面的代码有效,我终于从一个简单的列表中检索数据,问题是当我获得查找列时,它显示的是对象而不是值。


       var ProductInfo = '';
       var listItemEnum = collListItem.getEnumerator();
       var section = oListItem.get_item("Section");

           while (listItemEnum.moveNext()) {

               if (oListItem.get_item('Section') === 'Πειραιως Leasing'){

               }

               var oListItem = listItemEnum.get_current();

               ProductInfo += '\n\nID: '+ oListItem.get_id() +
                   '<\nTitle: ' + oListItem.get_item('Title') +
                   '\nLink: ' + oListItem.get_item('Link') +
                   '<\nSection>' + oListItem.get_item('Section').get_lookupValue();
       }

       var value = SP.FieldLookup.get_lookupField ('Section');
       console.log(value);

       alert(ProductInfo.toString());
   }

   function onQueryFailed(sender, args) {
       alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
   }
   </script><input type="button" value="Get Section" onclick="getSection()"/>```

标签: javascriptsharepoint

解决方案


由于您已经设置了 var section = oListItem.get_item("Section") 再次使用该变量。这应该是您正在寻找的。

   var ProductInfo = '';
   var listItemEnum = collListItem.getEnumerator();

       while (listItemEnum.moveNext()) {

           if (oListItem.get_item('Section') === 'Πειραιως Leasing'){

           }

           var oListItem = listItemEnum.get_current();
           var section = oListItem.get_item("Section");
           ProductInfo += '\n\nID: '+ oListItem.get_id() +
               '<\nTitle: ' + oListItem.get_item('Title') +
               '\nLink: ' + oListItem.get_item('Link') +
               '<\nSection>' + section.get_lookupValue();
   }

     console.log(section.get_lookupId());
     console.log(section.get_lookupValue());

   alert(ProductInfo.toString());
   }
   function onQueryFailed(sender, args) {
       alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
   }

推荐阅读