如何解决如果对象数组不包含具有此 ID 的对象,如何返回 true?
我正在尝试查找数组是否不包含具有所选标签 ID 的标签,然后返回 true。但是此代码不起作用。
!this.product.tags.includes(
tag =>
tag.type === 'shoes' &&
tag.Id === this.selectedProduct[item][1].tag.Id,)
出了什么问题,如何修复?
解决方法
def run():
import apache_beam as beam
options = PipelineOptions([
"--runner=FlinkRunner","--flink_version=1.10","--flink_master=localhost:8081","--environment_type=EXTERNAL","--environment_config=localhost:50000","--streaming","--flink_submit_uber_jar"
])
options.view_as(SetupOptions).save_main_session = True
options.view_as(StandardOptions).streaming = True
with beam.Pipeline(options=options) as p:
(p
| 'Create words' >> ReadFromKafka(
topics=['mullerstreamer'],consumer_config={
'bootstrap.servers': '192.168.49.1:9092,192.168.49.1:9093','auto.offset.reset': 'earliest','enable.auto.commit': 'true','group.id': 'BEAM-local'
}
)
| 'print' >> beam.Map(print)
)
if __name__ == "__main__":
run()
是错误的内置函数,您正在寻找 includes
some
!this.product.tags.some(
tag =>
tag.type === 'shoes' &&
tag.Id === this.selectedProduct[item][1].tag.Id,)
checks if the provided argument exists in the given array。
includes
checks if any of the elements of the array evaluate to true with the provided function.
!this.product.tags.includes.some(
tag =>
typeof( tag.type )=== (typeOfvar) &&
tag.Id === this.selectedProduct[item][1].tag.Id,)
对我也有用!我已经用 typeof 更改了 tag.type。这可以帮助您使代码更加生动。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。