I am trying to concatenate a variable that I pull with a Redux selector into a string, which ultimately reads a URL.
I seem to be getting the syntax wrong, as I keep getting results for just the string "ticker" or nothing at all.
Could someone advise me on this?
I have tried the following but to no avail:
'string ${variable} string';
{'string' + variable + 'string'}
'string' + {variable} + 'string'
My code:
const { selectedTicker } = useSelector(navigationSelector.all);
const selectUrl = 'https://openapi.naver.com/v1/search/news.json?query=${selectedTicker}&display=5&start=1&sort=sim';
Thanks in advance!
Use Template Literals.
That key above your "Tab" Key. Use That. And then wrap around your string with it.
Here.
const selectUrl = `https://openapi.naver.com/v1/search/news.json?query=${selectedTicker}&display=5&start=1&sort=sim`;
Related
I'm and Old man trying to learn a new trick. 1st post. be merciful please. I keep getting this Message. Ive tried console logging it (line 13) get the same message.
All i want is to pull High low data from the openweather site for a designated city named in A2 of my spreadsheet.
The log isnt showing my API key or the location from the A2 location. ive looked at this for 2 hours and my eyes are crossing. Like i said im new. Im sure its something i have done wrong. Thanks in advance.
Message Exception: Invalid argument: http://api.openweathermap.org/data/2.5/weather?q={location}&appid=${key} (line 14, file "Code")
function getCurrentData() {
//API key
const key = "API key Here(actually a number)"
const ss = SpreadsheetApp.getActiveSpreadsheet()
const wsLocation = ss.getSheetByName("Location")
const wsLiveData = ss.getSheetByName("Live Data")
const location = wsLocation.getRange("A2").getValue()
const highCell = wsLiveData.getRange("B4")
const lowCell = wsLiveData.getRange("C4")
let apiURL = 'https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${key}'
//console.log(apiURL)
const resText = UrlFetchApp.fetch(apiURL).getContentText()
console.log(resText)
}
The issue appears due to fetching an invalid url.
Noting in the url that syntax ${} appears, you were attempting to define the url using template literals in a normal string.
To define a template literal string you should use the backtick character ( ` ) instead of quote character ( ' ).
More information about template literals can be found here:
Template literals (Template strings)
I mean when we initialize Selector like this:
let stringLocator = 'some element locator'
selector = new Selector(stringLocator)
is that possible to get original string locator somehow like this:
selector.locator
p.s. This question is related to this one where I've found some hacky workarounds to get testcafe display my xpath locators in error.
Testcafe does not support this, but you can use the following approach
function createSelector (locator) {
return Object.assign(Selector(locator), { locator });
}
const selector = createSelector('#button');
console.log(selector.locator)
I had the same issue yesterday. The apiFnChain contains the fnChain you used for the selector. It is behind a symbol. This is what helped me. Maybe this will help you too.
const selector = Selector('button.explore-button').withText('Explore the site')
const selectorFnChain = selector[Object.getOwnPropertySymbols(selector)[0]].options.apiFnChain
console.log(selectorFnChain)
This will give you this:
Selector('button.explore-button'),.withText('Explore the site')
You don't have to get the entire chain but this was the most helpful for me.
Ok I hope this has a simple solution.
I am trying to make a validation with Vuelidate on a field to be different than an array of strings.
So - sending a single string is working: not(sameAs(() =>"hello"))
But trying to send an array or comma seperated values wont validate anymore :not(sameAs(() => ["hello", "helloo"])) or not(sameAs(() => "hello", "helloo")).
Hopefully someone can help me, Thanks!
Alright if anyone is interested -
I just created my own validator ->
usedTitles:['hello','helloo'];
const checkDuplicates = () => this.usedTitles.indexOf(this.val) === -1;
val.unique = checkDuplicates;
I'm trying to get a vuejs store variable like this :
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls.${pathFile};
So in the second line ${pathFile} is not interpreted in that way. Please could you help on how to write this ?
In JavaScript ${string_name} is used inside template strings (1). If you want to access the value of a dictionary based on a string's content you should use the square brackets syntax. In your case
this.$store.state.url[path_file]
On a side note I suggest you to use store getters to access variables.
(1): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
pathFile is a normal variable. Remove the brackets from it.
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls.pathFile;
you need to modify your code remove brackets from parameters.urls.${pathFile} to .urls.pathFile;
here is code..
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls.pathFile;
That's not valid javascript. I am guessing you meant to write the following:
const pathFile = `#pathFile_${this.devisDTO.code_produit}`;
const pathApp = this.$store.state.parameters.urls[pathFile];
I just do not know how the code works in below, mind if any one can tell me how its working this?? I do not understand especially "=>" what does this do?
React.Children.map(this.props.children, (child) => {};
This is an arrow expression. It creates a function. There's nothing in the curly braces, so no code will execute. It's part of JavaScript, not React Native-related.
For example, you could write a function named myFunction like this:
var myFunction = (name) => {
console.log("Hello, " + name);
}
See the MDN docs for more info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions