"background-image:url("+bg+")" , what is the + sign for ? Vue.js - vue.js

"background-image:url("+bg+")" , what is the + sign for ? Vue.js
as title . i dont understand why there are + sign added in url() ?
computed:{
content_bg(){
return "background-image:url(" + this.poiInfo.head_pic_url + ")"
},
any answer will be appreciated!

The + sign is not for the url. It is being used as string concatenation operator here. It adds the second string at the end of the first string. For example "a" + "b" equals "ab".
Your function is returning an string. If the value of this.poiInfo.head_pic_url is, lets says, www.example.com/head_pic then your function content_bg() will return a string value of background-image:url(www.example.com/head_pic).
content_bg(){
return "background-image:url(" + this.poiInfo.head_pic_url + ")"
},

Related

Create a newline from computed string

I would like to know how to add a newline in a computed string with the concatenation of string values. I need the values to be this.
1111 Ave, Apt 107
Iowa mycity, myzip
Here's what I have.
companyAddress()
{
return this.lead.address + ", " + this.lead.address2 + '\n' +
this.lead.state + ", " + this.lead.city + " " + this.lead.zip;
}
I get values no problem, but I can't get the \n to separate to two lines.
You can use v-html in your template.
<span v-html="companyAddress"></span>
companyAddress() {
return `${this.lead.address, ${this.lead.address2} <br> ${this.lead.state}, ${this.lead.city} ${this.lead.zip}`;
}

how to remove all html characters in snowflake, dont want to include all html special characters in query (no hardcoding)

Want to remove below kind of characters from string..pl help
'
&
You may try this one to remove any HTML special characters:
select REGEXP_REPLACE( 'abc&def³»ghi', '&[^&]+;', '!' );
Explanation:
REGEXP_REPLACE uses regular expression to search and replace. I search for "&[^&]+;" and replace it with "!" for demonstration. You can of course use '' to remove them. More info about the function:
https://docs.snowflake.com/en/sql-reference/functions/regexp_replace.html
About the regular expression string:
& is the & character of a HTML special character
[^&] means any character except &. Tthis prevents to REGEXP to replace all characters between the first '&' char and last ';'. It will stop when it see second '&'
+ means match 1 or more of preceding token (any character except &)
; is the last character of a HTML special character
CREATE or REPLACE FUNCTION UDF_StripHTML(str varchar)
returns varchar
language javascript
strict
as
'var HTMLParsedText=""
var resultSet = STR.split(''>'')
var resultSetLength =resultSet.length
var counter=0
while(resultSetLength>0)
{
if(resultSet[counter].indexOf(''<'')>0)
{
var value = resultSet[counter]
value=value.substring(0, resultSet[counter].indexOf(''<''))
if (resultSet[counter].indexOf(''&'')>=0 && resultSet[counter].indexOf('';'')>=0)
{
value=value.replace(value.substring(resultSet[counter].indexOf(''&''), resultSet[counter].indexOf('';'')+1),'''')
}
}
if (value)
{
value = value.trim();
if(HTMLParsedText === "")
{
HTMLParsedText = value
}
else
{
if (value) {
HTMLParsedText = HTMLParsedText + '' '' + value
}
}
value=''''
}
counter= counter+1
resultSetLength=resultSetLength-1
}
return HTMLParsedText';
to call this UDF :
Select UDF_StripHTML(text)

How to dynamically generate SQL query column names and values from arrays?

I have about 20 columns in one row and not all columns are required to be filled in when row created also i dont want to cardcode name of every column in SQL query and on http.post request on frontend. All values are from form. My code:
var colNames, values []string
for k, v := range formData {
colNames = append(colNames, k)
values = append(values, v)
}
Now i have 2 arrays: one with column names and second with values to be inserted. I want to do something like this:
db.Query("insert into views (?,?,?,?,?,?) values (?,?,?,?,?,?)", colNames..., values...)
or like this:
db.Query("insert into views " + colNames + " values" + values)
Any suggestions?
Thanks!
I assume your code examples are just pseudo code but I'll state the obvious just in case.
db.Query("insert into views (?,?,?,?,?,?) values (?,?,?,?,?,?)", colNames..., values...)
This is invalid Go since you can only "unpack" the last argument to a function, and also invalid MySQL since you cannot use placeholders (?) for column names.
db.Query("insert into views " + colNames + " values" + values)
This is also invalid Go since you cannot concatenate strings with slices.
You could fromat the slices into strings that look like this:
colNamesString := "(col1, col2, col3)"
valuesString := "(val1, val2, val3)"
and now your second code example becomes valid Go and would compile but don't do this. If you do this your app becomes vulnerable to SQL injection and that's something you definitely don't want.
Instead do something like this:
// this can be a package level global and you'll need
// one for each table. Keep in mind that Go maps that
// are only read from are safe for concurrent use.
var validColNames = map[string]bool{
"col1": true,
"col2": true,
"col3": true,
// ...
}
// ...
var colNames, values []string
var phs string // placeholders for values
for k, v := range formData {
// check that column is valid
if !validColNames[k] {
return ErrBadColName
}
colNames = append(colNames, k)
values = append(values, v)
phs += "?,"
}
if len(phs) > 0 {
phs = phs[:len(phs)-1] // drop the last comma
}
phs = "(" + phs + ")"
colNamesString := "(" + strings.Join(colNames, ",") + ")"
query := "insert into views " + colNamesString + phs
db.Query(query, values...)

How to use variables in modal function's position option in SimpleModal 1.4.4

I am having an issue inserting variables into the modal functions position option. The following works:
$.modal('<iframe id = "framedetails" src="' + src + '" height="' + vHeight + 'px;" width="' + vWidth + 'px;" style="border:0"></iframe>', {
closeHTML:"<a href='#' class='modalCloseImg' alt='Close/Cancel' title='Close/Cancel'><a>", //add close button
fixed: false,
position: ["75px","595.5px"],
overlayClose:false
});
How would I insert a variable for each of the position values? I am unable to get the concatenation correct and have tried many variations.
For example, position: ["" + vTop + "","" + vLeft + ""] seems to insert the value for vTop but the vLeft variable is not being applied. If I supply the actual value in this for vLeft, it works as expected. What am I missing here?
I figured this out...pretty silly of me. I just create a string array of the two variables (vTop and vLeft) and passed them in.
vArray = ["" + vTop + "","" + vLeft + ""];
...
position: vArray

Use of a string to get information in an associative array

I've got a function that takes two strings as arguments, and I want to use these arguments to get the data held in associative arrays.
var myVar:Object = {};
myVar.value = 10;
function getStuff(v:String, vl:String){
//...
}
In this case, v = "myVar" and vl = "value".
How do I translate vinto the variable name 'myVar' and v1 into 'value' so that I can access the data?
Sorry if this won't work, for I can only test AS3 here, but please try this:
function getStuff(v:String, vl:String){
return eval(v + "." + vl);
}
eventually
function getStuff(v:String, vl:String){
return eval("_gobal." + v + "." + vl);
}