sharepoint - 在 Sharepoint 中使用 pnp 搜索检索列表元素
问题描述
这是在 Sharepoint 中使用 pnp 搜索检索列表元素的正确方法吗
pnp.sp.search("ListName").then((r: SearchResults) => {
console.log(r.ElapsedTime);
console.log(r.RowCount);
console.log(r.PrimarySearchResults);
});
解决方案
搜索是直接从根 sp 对象访问的,可以采用表示查询文本的字符串、与SearchQuery
接口匹配的普通对象或SearchQueryBuilder
实例。前两个如下所示。
import pnp, { SearchQuery, SearchResults } from "sp-pnp-js";
// text search using SharePoint default values for other parameters
pnp.sp.search("test").then((r: SearchResults) => {
console.log(r.ElapsedTime);
console.log(r.RowCount);
console.log(r.PrimarySearchResults);
});
// define a search query object matching the SearchQuery interface
pnp.sp.search(<SearchQuery>{
Querytext: "test",
RowLimit: 10,
EnableInterleaving: true,
}).then((r: SearchResults) => {
console.log(r.ElapsedTime);
console.log(r.RowCount);
console.log(r.PrimarySearchResults);
});
搜索 Office 365 组。为确保您在 Office 365 中搜索所有组,请参阅下面的示例,其中包括 " EnableDynamicGroups
" 属性。
import pnp, { SearchQueryBuilder, SearchResults, SearchQuery } from "sp-pnp-js";
const _searchQuerySettings: SearchQuery = {
TrimDuplicates: false,
RowLimit: 500,
SelectProperties: ["Title", "SPWebUrl", "projectID"],
Properties: [{
Name: "EnableDynamicGroups",
Value: {
BoolVal: true,
QueryPropertyValueTypeIndex: 3
}
}]
}
let q = SearchQueryBuilder.create("ContentType:ProsjektInformasjon", _searchQuerySettings).rowLimit(500);
pnp.sp.search(q).then(res => {
console.log(res.PrimarySearchResults.length);
console.dir(res.PrimarySearchResults)
});
推荐阅读
- python - 最小化python字符串中的单词数量
- mysql - 如何通过具有不同的数据透视表对列求和 - Laravel/Eloquent
- ios - iOS - 通用链接 - 防止浏览器中的重定向打开已安装的应用程序
- google-contacts-api - 这些是联系人 API 搜索方法的 People API 中的一个很好的替代品吗?
- python - 使用 pd.to_numeric 将 bool dtype 向下转换为 float
- python - 如何解决 SettingWithCopyWarning:试图在 DataFrame 中的切片副本上设置值
- python - 基于具有国家计数值的数据框的彩色地图
- django - django-export 数据真实值而不是foreign_id
- reactjs - 服务人员无法控制客户端
- emacs - emacs lisp中的`let loop`(命名为let)替代方案