Различия
Показаны различия между двумя версиями страницы.
| Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
| develop:mule:dataweave [2024/02/25 18:46] – [Types] mirocow | develop:mule:dataweave [2024/03/06 22:19] (текущий) – [Ссылки] mirocow | ||
|---|---|---|---|
| Строка 19: | Строка 19: | ||
| <note tip>IDE https:// | <note tip>IDE https:// | ||
| + | ===== Oprators ===== | ||
| + | |||
| + | * using: For initializing local variables in a DataWeave script. | ||
| + | * Unary DataWeave operators at this level: | ||
| + | * .^: Schema selector. | ||
| + | * .#: Namespace selector. | ||
| + | * ..: Descendants selector. | ||
| + | * not: Logical operator for negation. | ||
| + | * .@: All attribute selector, for example, in a case that uses the expression payload.root.a.@ to return the attributes and values of the input payload < | ||
| ==== Condition ==== | ==== Condition ==== | ||
| Строка 279: | Строка 288: | ||
| * **takeWhile** Selects elements from the array while the condition is met but stops the selection process when it reaches an element that fails to satisfy the condition. | * **takeWhile** Selects elements from the array while the condition is met but stops the selection process when it reaches an element that fails to satisfy the condition. | ||
| + | === divideBy === | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import divideBy from dw:: | ||
| + | output application/ | ||
| + | --- | ||
| + | { " | ||
| + | </ | ||
| + | === drop === | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import * from dw:: | ||
| + | var samplearray = [" | ||
| + | output application/ | ||
| + | --- | ||
| + | |||
| + | drop(samplearray, | ||
| + | </ | ||
| + | |||
| + | === indexOf === | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import * from dw:: | ||
| + | var samplearray = [" | ||
| + | output application/ | ||
| + | --- | ||
| + | |||
| + | indexOf(samplearray, | ||
| + | </ | ||
| + | |||
| + | === join === | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import * from dw:: | ||
| + | |||
| + | var items = [{id: " | ||
| + | |||
| + | var Prices = [{Id: " | ||
| + | |||
| + | output application/ | ||
| + | --- | ||
| + | join(items, Prices, (item) -> item.id, (price) -> price.Id) | ||
| + | |||
| + | </ | ||
| + | === takeWhile === | ||
| + | |||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import * from dw:: | ||
| + | output application/ | ||
| + | var arr = [1, | ||
| + | --- | ||
| + | |||
| + | arr takeWhile $ <= 2 | ||
| + | |||
| + | </ | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import * from dw:: | ||
| + | output application/ | ||
| + | var obj = { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | --- | ||
| + | obj takeWhile ((value, key) -> value < 3) | ||
| + | </ | ||
| ==== dw::Core ==== | ==== dw::Core ==== | ||
| Строка 292: | Строка 376: | ||
| --- | --- | ||
| payload distinctBy $.id | payload distinctBy $.id | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | output application/ | ||
| + | var str = [1, | ||
| + | var str1= [4,5,6,7,1] | ||
| + | --- | ||
| + | (str ++ str1) distinctBy ((item, index) ->item ) | ||
| </ | </ | ||
| Строка 559: | Строка 652: | ||
| </ | </ | ||
| + | < | ||
| + | %dw 2.0 | ||
| + | output application/ | ||
| + | --- | ||
| + | payload filterObject ((value, key) -> | ||
| + | (key as String != "first name" | ||
| + | and (key as String != "last name") | ||
| + | ) | ||
| + | </ | ||
| === flatten === | === flatten === | ||
| Строка 677: | Строка 779: | ||
| </ | </ | ||
| + | < | ||
| + | %dw 2.0 | ||
| + | output application/ | ||
| + | fun process(obj: | ||
| + | (key): key match { | ||
| + | case " | ||
| + | else -> value | ||
| + | } | ||
| + | }) | ||
| + | --- | ||
| + | payload map ((item, index) -> | ||
| + | process(item) | ||
| + | ) | ||
| + | </ | ||
| === mapObject === | === mapObject === | ||
| Строка 830: | Строка 946: | ||
| So result will be 9 | So result will be 9 | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | output application/ | ||
| + | |||
| + | var data = {" | ||
| + | --- | ||
| + | data..value reduce $ | ||
| </ | </ | ||
| Строка 987: | Строка 1112: | ||
| * **valueSet** Returns an array of the values from key-value pairs in an object. | * **valueSet** Returns an array of the values from key-value pairs in an object. | ||
| + | === everyEntry === | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import everyEntry from dw:: | ||
| + | output application/ | ||
| + | --- | ||
| + | { | ||
| + | a: {} everyEntry (value, key) -> value is String, | ||
| + | b: {a: "", | ||
| + | c: {a: "", | ||
| + | d: {a: "", | ||
| + | e: {a: "" | ||
| + | f: null everyEntry ((value, key) -> key as String == " | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === mergeWith === | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import mergeWith from dw:: | ||
| + | output application/ | ||
| + | --- | ||
| + | { " | ||
| + | </ | ||
| + | |||
| + | === someEntry === | ||
| + | |||
| + | < | ||
| + | %dw 2.0 | ||
| + | import someEntry from dw:: | ||
| + | output application/ | ||
| + | --- | ||
| + | { | ||
| + | a: {} someEntry (value, key) -> value is String, | ||
| + | b: {a: "", | ||
| + | c: {a: "", | ||
| + | d: {a: "", | ||
| + | e: {a: "" | ||
| + | f: null someEntry (value, key) -> key as String == " | ||
| + | } | ||
| + | </ | ||
| ==== dw:: | ==== dw:: | ||
| Строка 1123: | Строка 1291: | ||
| * https:// | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||