This isn’t a terribly technical jaunt, but it’s one worth writing down. I had a problem with a select menu in a web app. The problem was that comma-separated input for the options of the select was being incorrectly parsed. For example, suppose I saved a record with the list [“one”, “two”, “three”] (formatted as “one,two,three” in the input field) as the options list for the select. Instead of a select with items
“one”, “two”, and “three”,
I got items
“o”, “n”, “e”, “,”, …
.split() method. That method takes an input. That input is used as a delimiter for the split function; every time it appears in the string, the function starts a new string. It returns an array containing the resulting segments, in a fashion similar to the PHP explode() function.
Now, the next question was this: how would I most easily get the array that I was going to create from that options string into the template where it belonged? While some think that Angular is singing its swan song—or has already sung it—criticism doesn’t negate the fact that Angular templates are very smart technology. That for-in construction doesn’t just allow iterations on scope variables; it allows iterations on the output of functions called on those variables. So instead of the options list being constructed out of
current as option for current in values
(there are reasons for that elaborate construction, but that’s another post and probably already published by somebody else), it could be
current as option for current in values.split(',')
Posted via UltraBlog.vim.