Handlebars Using #root in Custom Helper - handlebars.js

I have a scenario where I am trying to access a separate element in my custom helper from within a nested for loop. When I use root outside my for loop I don't have any issues, but I can't seem to use #root within my custom helper. I thought maybe ../ would work, but it appears that is only be moving up to the parent element, not a one that is separate
Here are my two objects:
category //Object being looped through
categoryQuery //Query object being compared to looped values
Here is my view (looping through ID's and then apply selected to the ID attached to categoryQuery:
{{#category}}
<option value="{{this.categoryId}}"{{selected this.categoryId #root.categoryQuery}}>{{this.categoryName}}</option>
{{/category}}
Preselected value if the values match:
/Preselect option value that is associated with edited record
hbs.registerHelper('selected', function(option, value){
if (option === value) {
return 'selected';
} else {
return '';
}
});
Updated:
when adding console.log('Option : ' + option + ' Value : ' + value); into the else statement of my registered helper, I receive the following, which shows that it isn't an issue that #root.category isn't pulling in the value, but it isn't equating correctly.
For example:
Option : 1 Value : 2
Option : 2 Value : 2
Option : 1 Value : undefined

I determined that the root cause of the issue was the strictness in the comparison operator. When changed to == I was able to correctly identify the ID's that matched

Related

How to extract a string value from an array using scripted field in kibana?

Is there a way to extract a string value from an array with the use of if statement in scripted field in kibana. I tried the below code, however, I am unable to filter out the correct and incorrect values in discover tab of kibana. This might be due to remark field is an array.
def result_string = "";
if (doc['nac.keyword'].value =="existing_intent" &&doc['remark.keyword'].value != "acceptable") {
result_string = "incorrect";
}
if (doc['nac.keyword'].value =="existing_intent" &&doc['remark.keyword'].value == "acceptable") {
result_string = "correct";
}
return result_string;`
You can use the contains method defined on Array to check for element membership:
!doc['remark.keyword'].value.contains("acceptable") //does not contain
For this, you might want to ensure first that doc['remark.keyword'].value is indeed an Array.

Need to reverse a repeat region

I have a firebase element that is pulling in the last 5 items
<firebase-element id="base" location="https://mydb.firebaseio.com/mydata" data="{{items}}" keys="{{keys}}" limit="5" ></firebase-element>
That is bound to this repeat region
<template repeat="{{id in keys}}">
<x-chat-list id="chatList" username="{{items[id]['uuid']}}" text="{{items[id]['text']}}" ></x-chat-list>
</template>
I simply need to reverse the order of the repeat region.
I think you just need to observe the array and reverse it (or store the reversed values in another attribute)
Ex :
keysChanged : function() { this.keys.reverse(); }
If the firebase-element sometimes changed the values in the array without triggering the keysChanged function, you can also use the observe object
Just add a custom Polymer expression, e.g.:
PolymerExpressions.prototype.revArray = function(a) {
return a.reverse();
}
and pipe your data to it:
<template repeat="{{id in keys | revArray}}">
Now you can use this anywhere since the expression handler is global.

Birt Crosstab Date Issue

I have a crosstab where one of the groups contains a date. When the date is NULL, i want to display a space, anything I've tried including the code below on the expression for the binding name of the field. Yet it still displays Jan 1, 0001. How can I get it to display a space instead when the value is NULL?
if (["Group5"]["CP_EXPIRATION_DATE"] == null ) {
" ";
} else {
dimension["Group5"]["CP_EXPIRATION_DATE"];
}
I am not sure you can do this in the binding expression because the datatype is a Date, therefore a blank space can't be set as value. You could always use a script for this, although there might be a more elegant way:
Click your expiration date field onto the crosstab-> Script tab -> onRender -> Enter a script such
if (dimension["Group5"]["CP_EXPIRATION_DATE"]==null){
this.setDisplayValue(" ")
}

Get list of post by specific position in query

I need create a loop with specifics post but I would like do it by position (not by id) of all of them. I want to use a single loop with specific position.
Example: (2, 5, 9, etc)
I tried to use wp_query methods but my php knowledge is little.
Outside the loop, create a counter variable:
$post_number = 1;
Then, while you're in the loop, you can check on the contents of the variable to see which post you are at. For instance, in the following example, only the first and second posts will be shown.
Just before you end the loop, add to the counter using $post_number++.
// Start loop
if ($post_number == 1 || $post_number == 2){
// standard loop contents ( the_title(), the_content(), etc)
}
$post_number++;
// stop loop
Why you not try inside a loop for an example:
if ($idpost == "4")
{
// print...
}

test if a variable is empty and give default value during qmake

How can you test if a variable is empty or not defined in a qmake .pro file? I want to
be able to set up a default value if the variable is not defined.
I tried
eval("VARIABLE" = ""){
VARIABLE = test
}
eval("VARIABLE" = ""){
message(variable is empty)
}
but I still get the message "variable is empty".
there is already the function isEmpty I didn't spot:
isEmpty(VARIABLE){
VARIABLE = test
}
isEmpty(VARIABLE ){
message(variable is empty)
}
I don't understand why eval didnt work thought...
Like your own answer says, isEmpty(VARIABLE) does what you want:
isEmpty(VARIABLE) {
...
}
The qmake language has no equivalent of an equals operator (==), but you can compare things like this:
equals(VARIABLE, foo) {
...
}
You can also check if a variable contains a substring, using a regular expression:
contains(VARIABLE, .*foo.*) {
...
}
The reason why eval() didn't work, is that it executes the statement within it and returns true if the statement succeeded.
So by doing this:
eval(VARIABLE = "") {
...
}
...you are actually assigning "" to VARIABLE, making the variable empty and entering the block.
More about test functions: http://qt-project.org/doc/qt-5/qmake-test-function-reference.html

Resources