palantir-foundry - TypeScript:仅返回 ObjectSet 的第一个值
问题描述
我对 TypeScript 非常陌生,尤其是对 Object(Sets) 的自定义 Palantir 实现。我要存档的内容:我想将 ObjectSet 过滤为某些特定值。然后我想返回这些值中的第一个。事实上,我只想返回一行。到目前为止我所做的:
@Function()
public nextUnprocessedValueString(inputObject: ObjectSet<CombinedSentencesForTagging>): ObjectSet<CombinedSentencesForTagging>{
const result = Objects.search().combinedSentencesForTagging().filter(f => f.customerFeedback.exactMatch('i like it very much.'))
return result
我只需要第一行(或随机行)。
谢谢!
解决方案
试试这个:
@Function()
public nextUnprocessedValueString(inputObject: ObjectSet<CombinedSentencesForTagging>): CombinedSentencesForTagging {
const result =
inputObject.filter(f => f.customerFeedback.exactMatch('i like it very much.'))
.orderBy(f => f.customerFeedback.asc())
.take(1);
return result[0];
}
以下是我对原始函数所做的更改:
- 将返回类型更改为单个
CombinedSentencesForTagging
对象。 - 修改了要在函数参数
filter
中指定的行上运行inputObject
- 使用
orderBy
andtake
filter 子句只选择一个过滤结果。
推荐阅读
- c# - SerializeException : 试图反序列化一个空流错误
- react-native - Algolia 和 React Native FlatList ListHeaderComponent
- scala - 在 Scala 中避免 asInstanceOf 的一种方法
- c# - 在 Task.IsCompleted 之后更好:await 或 Result
- python - 将所有标签值远离轴
- c# - 命令“call npm run build-templates”退出,代码为 134
- php - 这是 PHP 空合并运算符中的错误还是预期行为?
- python - 数据框中的乘法
- ios - Lottie 动画没有出现 iOS
- reactjs - 我想使用带有反应的复选框从列表中删除一个项目