如何在JavaScript中设置Google Protobuf重复字段

发布于 2025-01-23 23:11:33 字数 155 浏览 6 评论 0 原文

例如,您有一个Google Protobuf消息客户,其中具有重复字段,如下所示。

message Customer {
  repeated int32 items = 1;
} 

如何在JavaScript中设置重复的项目字段?

For example, you have a google protobuf message Customer with repeated field like below.

message Customer {
  repeated int32 items = 1;
} 

How do you set the repeated items field in javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静被遗忘 2025-01-30 23:11:33

要在JavaScript中设置重复的字段,

您可以使用setItemslist或AddItems方法。

例如,使用setItemslist方法

 让客户= new Customer();
customer.setitemslist([[12,123,1234]);
 

它将将项目的值设置为JavaScript数组。

或另一个示例,使用additems方法

 让客户= new Customer();
customer.additems(123);
 

它将将123的值附加到消息中的项目列表。

有关更多信息,您可以查看中。

To set the repeated field in javascript,

You can use either setItemsList or addItems methods.

For example, to use setItemsList method

let customer = new Customer();
customer.setItemsList([12, 123, 1234]);

It will set the value of items to the javascript array.

Or for another example, to use addItems method

let customer = new Customer();
customer.addItems(123);

It will append the value of 123 to the list of items in the message.

For more info, you can check out the protobuf docs for repeated field in javascript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文