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];
Related
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`;
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)
My url re-updating after the push
I want to make this url:
www.abc.com/istanbul-taksim-otelleri?checkin=2019-05-08&checkout=2019-05-16&filters=meal_types:full,half,etc;stars:1,2,4
const query = {
checkin: '2019-05-08',
checkout: '2019-05-16',
filters:'meal_types:full,half,etc;stars:1,2,4'
}
this.router.push({query})
after this gettin like this
www.abc.com/istanbul-taksim-otelleri?checkin=2019-05-08&checkout=2019-05-16&filters=meal_types%3Afull,half,etc%3Bstars%3A1,2,4
do you have any idea ? how can fix it ?
See https://w3schools.com/tags/ref_urlencode.asp - %3A is just a URL-encoded colon. URL-encoding Strings is standard practice, and in most cases required in order to make a valid URL.
If you need to decode a URL, something like decodeURIComponent() could work for you, e.g.:
const uri = 'www.example.com/:";[]}'
const encodedURI = encodeURIComponent(uri)
console.log(encodedURI)
const decodedURI = decodeURIComponent(encodedURI)
console.log(decodedURI)
I am reviewing an app build in Vuejs (I am not a vue developer), so be patient with me.
I found this line of code:
const {property, $rxFirebase: {actions: {properties}}} = this
I guess this works as in other languages. "This" is assigning values to the object in the left.
I am trying to read also {sources: {properties}}, so I have added the code like this:
const {property, $rxFirebase: {actions: {properties}, sources: {properties}}} = this
But when I build it, I get an error:
Module build failed: Duplicate declaration "properties"
Any ideas?
This is not just assignment its destructuring assignment.
This line:
const {property, $rxFirebase: {actions: {properties}}} = this
is equivalent to
const property = this.property, properties = this.$rxFirebase.actions.properties;
So you can not add another properties variable because it is already declared. You should add different name for second properties declaration, like this:
const {property, $rxFirebase: {actions: {properties}, sources: {properties: myProperties }}} = this; // where myProperties some name for variable
console.log(myProperties === this.$rxFirebase.sources.properties); // true
I'm trying to remove all entities from a contentState.
What would be the prefered way to do that?
Not sure what the canonical way is, but I've been able to do it by using Modifier.applyEntity(): https://draftjs.org/docs/api-reference-modifier#applyentity.
You basically need to loop through all the blocks, and use that method on the entire range of text in each block. So something like this:
import {Modifier, SelectionState} from 'draft-js';
function clearEntityRanges(contentState){
contentState.getBlockMap().forEach(block => {
const blockKey = block.getKey();
const blockText = block.getText();
// You need to create a selection for entire length of text in the block
const selection = SelectionState.createEmpty(blockKey);
const updatedSelection = selection.merge({
//anchorOffset is the start of the block
anchorOffset: 0,
// focustOffset is the end
focusOffset: blockText.length
})
Modifier.applyEntity(contentState, updatedSelection, null);
});
return contentState
}