I have some strings which I get from a JSON file. Some of them contain the special chracters "-", "--" or are empty
{
"title": "Rihanna - Pour it up"
},
{
"title" : "Lady Gaga -- Bad Romance"
},
{
"title" : "Live from Golden Globes"
}
So, I have this registerhelper:
Handlebars.registerHelper('titleSplit', function(title) {
if(title.indexOf('-') === -1){
return new Handlebars.SafeString("<h2>" + title + "</h2>" + "<br />" + "<h2> </h2>");
}
if(title.indexOf('--') === -2){
var t = title.split(" -- ");
return new Handlebars.SafeString("<h2>" + t[1] + "</h2>" + " <br/> " + "<h2>" + t[0] + "</h2>");
}
else {
var t = title.split(" - ");
return new Handlebars.SafeString("<h2>" + t[1] + "</h2>" + " <br/> " + "<h2>" + t[0] + "</h2>");
}
});
and in my Handlebars HTML template:
<div>
{{titleSplit title}}
</div>
it kind of works alright, except that the titles with -- are getting displayed like this:
Undefined
Lady Gaga -- Bad Romance
What could be the issue here?
Im not completely sure on what your desired output should be. But here is the working helper and output
Handlebars.registerHelper('titleSplit', function(title) {
var titles;
if(title.indexOf(' - ') >= 0){
titles = title.split(' - ');
} else if(title.indexOf(' -- ') >= 0){
titles = title.split(' -- ');
} else {
titles = title.split();
titles[1] = '';
}
return new Handlebars.SafeString(
"<h2>" + titles[1] + "</h2>" + " <br/> " + "<h2>" + titles[0] + "</h2>");
});
//output
Pour it up
Rihanna
Bad Romance
Lady Gaga
Live from Golden Globes
Related
I want to run loop in Firebase function
sample data set:
I want to loop through it and print
console.log hello
Output should be like:
Try this;
sampleDataSet.forEach((d)=>{
console.log("Hello " + d.firstName + " " + d.lastName);
})
if sampleDataSet is an object then we can loop object as well;
for (let [key, value] of Object.entries(sampleDataSet)) {
console.log("Hello " + value.firstName + " " + value.lastName);
}
database.ref("collection").once("value").then((snapshot) => {
snapshot.forEach((userSnap) => {
console.log('hello ' + userSnap.child(`firstName`).val() + ' ' + userSnap.child(`lastName`).val() );
});
});
I have one problem with my code I can not achieving mobile no from my code :
OleDbCommand cmdoledb = new OleDbCommand("Select [Phone(R)] from [nil$] where [Code]='" + treadcode + "' ", oledbConn);
mobileno = cmdoledb.ExecuteScalar().ToString();
string message = "Dear " + clientname + " Your BSE Trade Position: " + Codemsg + " Ledger balance is : " + purebalance + ". (Aadinath)";
Int64 len = message.Length;
if (!string.IsNullOrEmpty(mobileno.Trim()))
{
dsmsg.Tables[0].Rows.Add(true, message, len, mobileno, clientname, treadcode);
}
else
{
dsmsg.Tables[0].Rows.Add(true, message, len,"No Mobile Found", clientname, treadcode);
}
this is my excel sheet screen shot :
I'm trying to use firebase function transaction, but as I see there is no official way to handle the first cached null value...
I'm trying to do the following:
var team = event.data.child('team').val();
var tip = event.data.child('tip').val();
console.log('tip: ' + tip + ' | team: ' +team)
const pathToValue = admin.database().ref('users/' + event.params.userId + '/coins');
const pathToTeamBetsValue = admin.database().ref('matches/' + event.params.matchId + '/opponents/' + team + "/bets");
return pathToValue.transaction(function (coins) {
if (coins) {
if (coins >= tip) {
pathToTeamBetsValue.transaction(function (teamBets) {
if (teamBets) {
teamBets = teamBets + tips;
return teamBets;
}
});
admin.database().ref('bets/' + event.params.matchId + '/' + event.params.userId + '/status').set('inProgress');
coins = coins - tip;
}
else {
console.warn(event.params.userId + " new bet on match " + event.params.matchId + " was not successfull! (not enough coin)")
//return coins;
}
}
return coins;
})
so far as you can see I get some value which what should be decreased from the user's coins... unfortunately till now I could only get the behaviour which sets null in the user's coin value.. please help
how to put white space before and after a character in text field
eg Text="John"
so i need whit space before and after John
You could try this:
SomeField.Text = " " + SomeField.Text + " ";
or using string.Format:
SomeField.Text = string.Format(" {0} ", SomeField.Text);
string InputValue = " " + MyTextBox.Text + " ";
Using Jquery, you could call this method...
function changeTxtBox(controlID) {
var oldValue = $(controlID).val();
var newValue = ' ' + result + ' ';
$(controlID).val(newValue)
}
I'm using advance search option in library project
Here is idea :
i have 6 different fields to allow search if i give the option for user to enter value in any of 6 option or enter combined fields how to use sql query to retrieve the value.
For example the fields are author, publication, price, subject, edition, bookid
and if user enter only one value i could search but if user enter more than one if i try combinations then there are many combination.
Please suggest me how to define the query?
you can do something like..
string strFilters = string.Empty;
if (author != "" )
{
strFilters += " Author = " + yourAuthorString + " and ";
}
if (publication != "")
{
strFilters += " publication = " + yourpublicationString + " and ";
}
if (price != "")
{
strFilters += " price = " + priceValue + " and ";
}
if (subject != "")
{
strFilters += " subject = " + yoursubjectString + " and ";
}
if (edition != "")
{
strFilters += " edition = " + youreditionString + " and ";
}
if (strFilters.Length > 3)
{
strFilters = strFilters.Remove(strFilters.Length - 5, 5);
}