'How to set google protobuf repeated field in 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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Henry Neo |
