简体   繁体   English

如何更新 Palantir Foundry Ontology 编辑函数中的数组属性?

[英]How do I update an array property in a Palantir Foundry Ontology edit Function?

I want to modify an array property on an Object using an Ontology Function (aka FoO), but I'm seeing the following error:我想使用本体函数(又名 FoO)修改对象上的数组属性,但我看到以下错误:

[typescript] Property 'push' does not exist on type 'readonly string[]'. [typescript] 类型“readonly string[]”上不存在属性“push”。

Looking at the generated TypeScript definition for my Object type, it looks like my array property has type ReadonlyArray<string> | undefined查看为我的 Object 类型生成的 TypeScript 定义,看起来我的数组属性的类型为ReadonlyArray<string> | undefined ReadonlyArray<string> | undefined

How can I update this array from my Function?如何从我的函数更新这个数组?

You need to assign a new value to the property rather than manipulate the existing array in-place.您需要为属性分配一个新值,而不是就地操作现有数组。

Array properties on an object type have immutable values to make the semantics for editing an array property clear: the only way to modify the values of an array property is to assign an entirely new array value.对象类型的数组属性具有不可变的值,以使编辑数组属性的语义清晰:修改数组属性值的唯一方法是分配一个全新的数组值。

If you want to manipulate the values of an array property, make a copy of it and update that (as described in the Foundry docs ):如果要操作数组属性的值,请对其进行复制并更新(如Foundry 文档中所述):

// Copy to a new array
let arrayCopy = [...myObject.myArrayProperty];
// Now you can modify the copied array
arrayCopy.push(newItem);
// Then overwrite the property value
myObject.myArrayProperty = arrayCopy;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为时间戳列创建 Palantir Foundry Fusion 同步? - How do I create a Palantir Foundry Fusion sync for a timestamp column? 如何在 Palantir Foundry 中使用 Function 对多个属性进行分组? - How can I groupby multiple properties using a Function in Palantir Foundry? 如何使用 Palantir Foundry 在 Pyspark 中编写 case 语句 - How do I write case statements in Pyspark using Palantir Foundry 如何在 Palantir Foundry Workshop 中创建累积和图? - How do I create a cumulative sum graph in Palantir Foundry Workshop? 如何在 Palantir Foundry 中解析 xml 文档? - How do I parse xml documents in Palantir Foundry? 在 Palantir Foundry 的 Workshop 中,如何清除之前保存的默认 Workshop 变量值? - In Palantir Foundry's Workshop, how do I clear the default Workshop variable values I saved earlier? 如何在 Pyspark 和 Palantir Foundry 中使用多个语句将列的值设置为 0 - How do I set value to 0 of column with multiple statements in Pyspark and Palantir Foundry Palantir Foundry 增量测试很难迭代,我如何更快地发现错误? - Palantir Foundry incremental testing is hard to iterate on, how do I find bugs faster? 在 Palantir Foundry 中,如何使用 OOMing 驱动程序或执行程序解析一个非常大的 csv 文件? - In Palantir Foundry how do I parse a very large csv file with OOMing the driver or executor? 在 Palantir Foundry 中,由于无法使用打印语句,我该如何调试 pyspark(或 pandas)UDF? - In Palantir Foundry, how do I debug pyspark (or pandas) UDFs since I can't use print statements?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM