I am trying to build a binding in an amp-list. What I need to do is extract the first entry in the array. For instance my json array looks like this:
"Ids": [
"123",
"456"
]
The amp-binding is looking like this:
[src]="'http://any.com?id=' + {{Ids}}"
I want this to end up like:
src="http://any.com?id=123
But is looks like this without any manipulation
src="http://any.com?id=123,456
Looking at the white listed functions, I wondering if I should use Array to String for this.
Related
Let's say I have a spinnaker parameter like this:
parameters.region = "us-east1,us-east2,us-west1"
I want to update a Configmap using that parameter, but I'd like to transform that into a list in my yaml file instead of just the string. Is there a way to do that with SPeL?
For instance, here's what I would like it to look like:
data:
regions.yaml: |
regions:
- us-east1
- us-east2
- us-west1
I see that there is a split(,) method I can use, but I can't figure out how I could loop over that in my output.
I have a question I'm sure it's something easy but I don't find solution.
I'm mapping an array of objects with objects looking like this:
{
categoryFr: "Commande",
categoryEn: "Order"
}
Now I want to to print this data in a div so if I do this, it works I get Commande:
<div>{categoryFr}</div>
But I want to dynamically render accordingly to the language I tried :
<div>`c.name${lang}`</div>
<div>`${c.name}${lang}`</div>
But the string categoryFr is printed instead of the value Commande.
you can access it with something like:
<div>{c[name + lang]}</div>
since obj.property (obj.categoryFr) is the equivalent with obj[property] (obj["category" + "Fr"])
I have two lists that look like this:
List("key1", "key2")
List("val1", "val2")
I'm trying to get it into this JSON-like format:
[{"key1":"val1"},{"key2","val2"}]
Right now, this is what I'm using:
val output = List(attrKeys.zip(attrValues).toMap)
But it gives me this:
[{"key1":"val1","key2":"val2"}]
How do I get this into a list of separate map objects?
attrKeys.zip(attrValues).map(Map(_))
I have an array made up of several strings that I am searching for in another array, like so:
strings_array = ["string1", "string2", "string3"]
main_array = [ ## this is populated with string values outside of my script ## ]
main_array.each { |item|
if strings_array.any? { |x| main_array.include?(x) }
main_array.delete(item)
end
}
This is a simplified version of what my script is actually doing, but that's the gist. It works as is, but I'm wondering how I can make it so that the strings_array can include strings made out of regex. So let's say I have a string in the main_array called "string-4385", and I want to delete any string that is composed of string- + a series of integers (without manually adding in the numerical suffix). I tried this:
strings_array = ["string1", "string2", "string3", /string-\d+/.to_s]
This doesn't work, but that's the logic I'm aiming for. Basically, is there a way to include a string with regex like this within an array? Or is there perhaps a better way than this .any? and include? combo that does the job (without needing to type out the complete string value)?
Thank you for any help!
You can use methods like keep_if and delete_if, so if you want to delete strings that match a regex you could do something like this:
array = ['string-123', 'test']
array.delete_if{|n| n[/string-\d+/] }
That will delete the strings in the array that do not match your regex. Same thing with keep_if method.
Hope it helps!
A good way to do this is with Regexp.union, which combines multiple regular expressions into a single regex handy for matching.
patterns = [/pattern1/, /pattern2/, /string-\d+/]
regex = Regexp.union(patterns)
main_array.delete_if{|string| string.match(regex)}
the below is the sample code in swift.
var loadedMessages = [[Message]]()
Message is a custom class. i'm not sure what [[Message]] () is doing.
It is specifying that your variable loadedMessages is an array of arrays that contains Message objects. A JSON representation of loadedMessages might look like:
loadedMessages: [
[ <Message>, <Message>, <Message> ],
[ <Message>, <Message>, <Message> ]
]
A quick Playground implementation of something similar can give you a pretty good introspection of the situation:
var foo = [[String]]()
foo.append(["bar"])
foo[0][0] // reveals "bar"
It means it’s an array of arrays of messages. Think of it in terms of whatever appears between the square brackets being an array of that, and this can include another array.
Alternatively, if you were to write out without the “shorthand” array syntax, it would be Array<Array<Messages>>().