I would like to use conditional binding in my XML view but have two conditions, such as this:
visible="{= ${viewModel>/selectedTabKey} === 'aaa' && ${viewModel>/editMode} === true}"
This is equivalent to the example here (escaped "&&"!).
But when running this, I do get this error:
BindingParser-dbg.js:341 Uncaught (in promise) SyntaxError: Expected '}' and instead saw '' in expression binding {= ${viewModel>/editMode} === true at position 34
What am I doing wrong?
Cheers
The only point I see in your sample is that
${viewModel>/editMode} === true
is redundant and should be simplified to
${viewModel>/editMode}
BUT your error message seems to point elsewhere since it explicitly shows another code
{= ${viewModel>/editMode} === true
(which is not in your sample)
Related
Error Message From JSON Checker:
Parse error on line 1:
< script type = "app
^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
My code on line 1:
< script type = "application/ld+json" > {
I'm no coder or programmer, just trying to dress up my website with some JSON enhancements and can't seem to find out what's wrong with line 1. Can anybody help?
I've looked all over the web for an answer and my code on line 1 appears to be correct.
I don't know what's wrong...
Is JSON Checker an external JSON Validator? To use it just try to validate what is inside of the script HTML element because that is the JSON. For example:
<script type = "application/ld+json">
{"Hello":"World"}
</script>
In this case you have to validate:
{ "Hello":"World" }
I hope this helps.
In my RoR app, I am trying to create a method that will look at a text field (body) and post a message to slack if a UK mobile phone number has been shared. I am testing for the UK mobile phone number by searching for 07 or '+447' appearing anywhere in the body text.
def contact_details_shared
if self.body.include? '07' || self.body.include? '+447'
slack_post(self)
end
end
This gives the following error when I try to launch the app in localhost (e.g. rails s):
syntax error, unexpected tSTRING_BEG, expecting keyword_then or ';' or '\n'
But I can't see any syntax issues here.
So I also tried the following
def contact_details_shared
if ( self.body.include? '07' || self.body.include? '+447' )
slack_post(self)
end
end
This gives the following error when I try to launch the app in localhost (e.g. rails s):
warning: string literal in condition
I was surprised by this because my code should be returning a boolean for each OR condition (not a string).
So... two questions:
1) How can I get the code to work?
2) I imagine there are solutions that are altogether more elegant than mine. Suggestions very welcome! Any ideas?
Try:
if self.body.include?('07') || self.body.include?('+447')
I suspect ruby needs the explicit identification of the arguments (i.e., '07' and '+447') provided by the use of parentheses.
See this magic:
Ex: "hello07".include? '07'
return true
when you use
"hello07".include? '+441'
returns false
"hello07".include? '07' || "hello07".include? '+441'
SyntaxError: (irb):39: syntax error, unexpected tSTRING_BEG, expecting end-of-input
"hello07".include? '07' || "hello07".include? "+441"
^
if you use "or" instead of ||
"hello07".include?'07' or "hello07".include?'+447'
returns true
if you want to work your code, you can use
if self.body.include?('07') or self.body.include?('+447')
the solution is use "or" instead of "||"
if you want use the "||" use this syntax
if (self.body.include?'07') || (self.body.include?'+447')
I am attempting to use a converter to modify a string in a jsrender template, but I can't seem to get the converter to work on a tag.
Using the example on JsRender API documentation Using converters for example, I have:
<script>
$.views.converters("upper", function(val) {
return val.toUpperCase();
});
</script>
Then in my HTML I have {{upper:Name}} which throws an error in the console: TypeError: val is undefined, and the template does not render at all.
However, if I apply the converter directly to a string like {{upper:"This should be uppercase"}} it outputs the string in uppercase as expected.
The {{:Name}} tag works fine by itself, so why isn't the converter working with it?
In case it is relevant, this is an ASP.NET-MVC project and the JSON data rendered by the template is coming from a $.post('#Url.Action(..,..)')... response. It's working perfectly until I attempt to apply the converter to the tag. Are converters not usable in this scenario?
It looks like your Name property is undefined in some case.
If you have a Name that is undefined, then {{:Name}} will render as the empty string, "" - but {{upper:Name}} will throw an error since undefined.toUpperCase() will fail.
You can investigate by breaking on thrown errors, (or by putting a break point or debugger statement in the converter) and seeing where your undefined Name is coming from.
You can also prevent the error getting thrown - and instead get error information rendered out - by any of the following techniques
write {{upper:Name onerror=true}} or {{upper:Name onerror='bad'}} (see https://www.jsviews.com/#onerror)
write
$.views.converters("upper", function(val) {
return val === undefined ? 'undefined' : val.toUpperCase();
});
write $.views.settings.debugMode(true);
and see what output you get, to investigate further about where your undefined Name is occuring.
I have a problem in my velocity template.
I have to show the image url for some products.
I set a variable in a right way. In some cases anyway I don't have this image, so I have to hide the image and put a blank space in the template.
I write the set variable in this way:
#set ($variantUrl = ${#if(!$product.getOrderFormImage().getUrl()) $!product.getOrderFormImage().getUrl() #else $product.getOrderFormImage().getUrl() #end} )
but I obtain a parse error:
Caused by: org.apache.velocity.exception.ParseErrorException:
Encountered "(" at
de.hybris.platform.commons.renderer.impl.VelocityTemplateRe
nderer[line 403, column 103] Was expecting:
...
I don't see any error in this line. What's the problem?
I'm not sure you can nest #if #else within #set - at least there's no mention of it in the Velocity user guide.
When I use your original expression I get the following error:
org.apache.velocity.exception.ParseErrorException: Encountered "#if" at ....
Was expecting:
<IDENTIFIER> ...
If I rewrite to make the #if #else to be the top-level statement such as:
#if( !$product.getOrderFormImage().getUrl() )
#set($variantUrl = $!product.getOrderFormImage().getUrl() )
#else
#set($variantUrl = $product.getOrderFormImage().getUrl() )
#end
this seems to do what you want, or at least it compiles and doesn't error! It's also a lot easier to read and understand.
Personally, I'd go one step further for the purpose of readability and use Velocity's shorthand notation for references:
#if( !$product.orderFormImage.url )
#set($variantUrl = $!product.orderFormImage.url )
#else
#set($variantUrl = $product.orderFormImage.url )
#end
The code below was created by me with the help of many SO veterans:
The code takes an entered math expression and splits it into operators and operands for later use. I have created two functions, the parsing function that splits, and the error function. I am having problems with the error function because it won't display my error messages and I feel the function is being ignored when the code runs. An error should print if an expression such as this is entered: 3//3+4,etc. where there are two operators together, or there are more than two operators in the expression overall, but the error messages dont print. My code is below:
def errors():
numExtrapolation,opExtrapolation=parse(expression)
if (len(numExtrapolation) == 3) and (len(opExtrapolation) !=2):
print("Bad1")
if (len(numExtrapolation) ==2) and (len(opExtrapolation) !=1):
print("Bad2")
def parse(expression):
operators= set("*/+-")
opExtrapolate= []
numExtrapolate= []
buff=[]
for i in expression:
if i in operators:
numExtrapolate.append(''.join(buff))
buff= []
opExtrapolate.append(i)
opExtrapolation=opExtrapolate
else:
buff.append(i)
numExtrapolate.append(''.join(buff))
numExtrapolation=numExtrapolate
#just some debugging print statements
print(numExtrapolation)
print("z:", len(opExtrapolation))
return numExtrapolation, opExtrapolation
errors()
Any help would be appreciated. Please don't introduce new code that is any more advanced than the code already here. I am looking for a solution to my problem... not large new code segments. Thanks.
The errors() function is called after parse() returns because it appears inside the body of parse(). Hopefully that is a typo.
For this particular input, numExtrapolate is appended with an empty buffer because there is no operand between / and /. That makes its length 4 and your check for Bad1 fails. So put a check like this
if buff:
numExtrapolate.append(''.join(buff))