Concat QML Properties with Javascript - javascript

I'm setting properties on QML items with java script, where "gaugetext" is a property of my QML object.
function finishCreation(setWidth,setHeight,setX,setY,setMinValue,setMaxValue,setDecPlace,setUnit,setID,SetValueObject,SetValueProperty) {
...
"gaugetext": Qt.binding(function(){return SetValueObject[SetValueProperty] + " " + setUnit})
....
}
This works well, but I want to set numbers of decimals. So I tried this:
"gaugetext": Qt.binding(function(){return "(" + SetValueObject[SetValueProperty]+ ")" + ".toFixed(" + setDecPlace + ")" + " " + setUnit})
But this results that the correct Value is shown with ".toFixed(value)".

You return a String "(<someValue>).toFixed(<someOtherValue>) <someThirdValue>".
You probably want to omit some of your " since you probably want to have the pieces that you mark as string to be executed instead.
return SetValueObject[SetValueProperty].toFixed(setDecPlace) + " " + setUnit
~~~(untetested)
Most likely however using a "finalize creation" function is a bad approach.

Related

Javascript .indexof 'typeError' error despite forcing string conversion

JS drives me insane with issues like this. I have the following code which creates a string (composed of session data and date information) to be written to an array, as such:
var _writes = String(req.session.subscriber + ":" + req.session.postal + "[" + req.session.id + "]=" + _onYear + "-" + _onMonth + "-" + _onDay + "-" + _onHour + "-" + _onMinute);
_users.push(_writes);
Later, I wish to perform an 'indexof' command on the string of the array, as such:
for (_cycle = 0; _cycle < _users.length; ++_cycle) {
_seeks = String(_users[_cycle]);
_score = _seeks.indexof("="); //ERROR THROWN HERE
//do other stuff here...
} //for loop
My error is "TypeError: _seeks.indexof is not a function"...? I thought by converting everything to a string I should be able to perform the 'indexof' command. Can somebody please advise what the issue is here? I thank you in advance.
Probably not a js issue. You are using "indexof" instead of "indexOf" (Uppercase O). Check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
It should be:
_seeks.indexOf("=");
Don't give up, it will make sense soon :)

How to delete an element from an array - Javascript P5

This is the way I add an element to my array
assets.push(house_location + " " + "Cost" + " " + cost + " " + "Downpay"+ " " + downpay)
Now I'm looking for a way to delete that same specific element from my array. Does someone know the code for this? So basically, the opposite of array.push
What you are looking for is the splice method.
If you want to remove the last item you pushed, use assets.pop(). If you want to remove that exact item like you said, you could do something like this:
assets.filter(d => d !== house_location + " " + "Cost" + " " + cost + " " + "Downpay"+ " " + downpay)
I'm guessing you are looking for these methods.
Array.shift() // Removes the first item from an array, and then returns the item removed.
Array.pop() // Removes the last item from an array, and then returns the item removed.
Array.splice() // I really can't be bothered to explain this one, so look at the link below.
The splice method.

I am unable to get environment names from an array

I have an array in which the environment list is stored and from this list, I have to get all the environment names which I am unable to get right now. See below what I have tried and please help me out of this.
<script>
//${environmentList} is getting from backend i.e from modal class in which toString() method has stored with all its contents.
var envLength = `${environmentList}`.length;
var allEnv = `${environmentList}`;
console.log("All Environments : " + allEnv);
console.log("Length of environments : " + envLength);
for(let i = 0 ; i < envLength ; i++){
let all = `${allEnv[i].environmentName}`;
console.log("Environment Name : " + all[i]);
}
</script>
toString() method :
#Override
public String toString() {
return "EnvironmentModel [environmentId=" + environmentId + ", environmentName=" + environmentName
+ ", environmentDesc=" + environmentDesc + ", hostAddress=" + hostAddress + ", environmentURL="
+ environmentURL + ", configFileName=" + configFileName + ", configFilePath=" + configFilePath
+ ", companyId=" + companyId + ", createdBy=" + createdBy + ", createdAt=" + createdAt
+ ", lastUpdatedBy=" + lastUpdatedBy + ", lastUpdatedAt=" + lastUpdatedAt + ", elementFileName="
+ elementFileName + ", elementFilePath=" + elementFilePath + ", envStatus=" + envStatus + ", projectId="
+ projectId + ", project=" + project + "]";
}
OUTPUT:
All Environments :
[EnvironmentModel [environmentId=345, environmentName=MM_Env_1, environmentDesc=Environment_1, hostAddress=null, environmentURL=null, configFileName=SystemFile.xml, configFilePath=/env_files/MM_Env_1, companyId=1, createdBy=2, createdAt=2019-12-18 16:39:38.595, lastUpdatedBy=2, lastUpdatedAt=2019-12-18 16:42:13.259, elementFileName=ElementFile.xml, elementFilePath=/env_files/MM_Env_1, envStatus=1, projectId=null, project=[Project [projectName=Magic Matrix, projectDescription=Magic Matrix is a significant and robust tool of the Solitera Software Company., projectId=23]]], EnvironmentModel [environmentId=346, environmentName=MM_Env_2, environmentDesc=Environment_2, hostAddress=null, environmentURL=null, configFileName=soapAPI_request_GetLyrics.xml, configFilePath=/env_files/MM_Env_2, companyId=1, createdBy=2, createdAt=2019-12-18 16:43:10.59, lastUpdatedBy=2, lastUpdatedAt=2019-12-18 16:43:58.522, elementFileName=Element.xml, elementFilePath=/env_files/MM_Env_2, envStatus=1, projectId=null, project=[Project [projectName=Magic Matrix, projectDescription=Magic Matrix is a significant and robust tool of the Solitera Software Company., projectId=23]]], EnvironmentModel [environmentId=347, environmentName=TM_Env_1, environmentDesc=TM_Env_1, hostAddress=null, environmentURL=null, configFileName=showcasetestData.xml, configFilePath=/env_files/TM_Env_1, companyId=1, createdBy=2, createdAt=2019-12-18 16:44:33.783, lastUpdatedBy=2, lastUpdatedAt=2019-12-18 16:44:47.09, elementFileName=soapAPI_request_TempConvert.xml, elementFilePath=/env_files/TM_Env_1, envStatus=1, projectId=null, project=[Project ...
Length of environments : 2235
Environment Name : undefined
Use Jackson json parser in Java class and in javascript side use JSON.parse to change the string to JSON object.
On the javascript side you'll should understand that the variable environmentList is a string and the length of the string is 2235 chars. To access each property you'll have to parse the string and turn it into an object.
As you are not relying on JSON you need to use String.split or a regex matcher.
But the simpler solution would be to convert the Environment variables into a JSON format. As the type of the output from System.getenv() is a Map<string, string> you can try this solution to create a JSON structure: Converting Map<String,String> into json
After that you'll either write the json in a script tag in HTML so it get's parsed directly, or user JSON parse on the string of the above solution.

Printing output to chrome console

Let's assume I have following javascript code:
<script type="text/javascript">
var x="function f(x){var i,o=\"\",l=x.length;for(i=0;i<l;i+=2) {if(i+1<l)o+=" +
"x.charAt(i+1);try{o+=x.charAt(i);}catch(e){}}return o;}f(\"ufcnitnof x({)av" +
" r,i=o\\\"\\\"o,=l.xelgnhtl,o=;lhwli(e.xhcraoCedtAl(1/)3=!84{)rt{y+xx=l;=+;" +
"lc}tahce({)}}of(r=i-l;1>i0=i;--{)+ox=c.ahAr(t)i};erutnro s.buts(r,0lo;)f}\\" +
"\"(0),4\\\"\\\\01\\\\0t\\\\\\\\\\\\03\\\\06\\\\03\\\\\\\\24\\\\03\\\\01\\\\" +
"\\\\4U03\\\\\\\\16\\\\0\\\\\\\\\\\\\\\\_\\\\0L00\\\\\\\\EY^MG[UWAWOJRD^ozrs" +
"u:'4K)I~vye.{P/ef&jospcmqsq14\\\\00\\\\03\\\\\\\\25\\\\06\\\\02\\\\\\\\37\\" +
"\\03\\\\01\\\\\\\\10\\\\07\\\\32\\\\05\\\\02\\\\\\\\37\\\\06\\\\00\\\\\\\\4" +
"W00\\\\\\\\35\\\\03\\\\01\\\\\\\\14\\\\02\\\\00\\\\\\\\14\\\\0}\\\\01\\\\0f" +
"\\\\2?;'.qiq)a&)V5LO27\\\\0C\\\\V[\\\\\\\\\\\\\\\\NZMD\\\"\\\\f(;} ornture;" +
"}))++(y)^(iAtdeCoarchx.e(odrChamCro.fngriSt+=;o27=1y%+;y+0)<4(iif){++;i<l;i" +
"=0(ior;fthnglex.l=\\\\,\\\\\\\"=\\\",o iar{vy)x,f(n ioctun\\\"f)\")" ;
while(x=eval(x));
</script>
When I run this script I get an output (an email address) on the chrome screen, that's simple. I would like to get same output in chrome's console.
For example, I use console.log("test"); to type test on console. Well, is it possible to type output (email address) to chrome console with javascript?
The code is using an obfuscating scheme based on successive evaluations of a string (using eval). It may be some kind of standard technique, but I am not familiar with it.
Initially, the code sets the value of variable x to a string:
var x = "function f(x){var i,o=\"\",l=x.length;for(i=0;i<l;i+=2) {if(i+1<l)o+=" +
"x.charAt(i+1);try{o+=x.charAt(i);}catch(e){}}return o;}f(\"ufcnitnof x({)av" +
" r,i=o\\\"\\\"o,=l.xelgnhtl,o=;lhwli(e.xhcraoCedtAl(1/)3=!84{)rt{y+xx=l;=+;" +
"lc}tahce({)}}of(r=i-l;1>i0=i;--{)+ox=c.ahAr(t)i};erutnro s.buts(r,0lo;)f}\\" +
"\"(0),4\\\"\\\\01\\\\0t\\\\\\\\\\\\03\\\\06\\\\03\\\\\\\\24\\\\03\\\\01\\\\" +
"\\\\4U03\\\\\\\\16\\\\0\\\\\\\\\\\\\\\\_\\\\0L00\\\\\\\\EY^MG[UWAWOJRD^ozrs" +
"u:'4K)I~vye.{P/ef&jospcmqsq14\\\\00\\\\03\\\\\\\\25\\\\06\\\\02\\\\\\\\37\\" +
"\\03\\\\01\\\\\\\\10\\\\07\\\\32\\\\05\\\\02\\\\\\\\37\\\\06\\\\00\\\\\\\\4" +
"W00\\\\\\\\35\\\\03\\\\01\\\\\\\\14\\\\02\\\\00\\\\\\\\14\\\\0}\\\\01\\\\0f" +
"\\\\2?;'.qiq)a&)V5LO27\\\\0C\\\\V[\\\\\\\\\\\\\\\\NZMD\\\"\\\\f(;} ornture;" +
"}))++(y)^(iAtdeCoarchx.e(odrChamCro.fngriSt+=;o27=1y%+;y+0)<4(iif){++;i<l;i" +
"=0(ior;fthnglex.l=\\\\,\\\\\\\"=\\\",o iar{vy)x,f(n ioctun\\\"f)\")";
Then it evaluates x and feeds the result back into eval until the return value is boolean false.
eval(x) yields this string:
"function f(x){var i,o="",ol=x.length,l=ol;while(x.charCodeAt(l/13)!=48){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return o.substr(0,ol);}f(")04,\"100\\t\\300\\630\\420\\310\\U430\\610\\\\\\_L000\\YEM^[GWUWAJODRo^rzus':K4I)v~ey{./Pfej&socpqmqs410\\030\\520\\620\\730\\310\\010\\7230\\520\\730\\600\\W400\\530\\310\\410\\200\\410\\}100\\f?2';q.qia))&5VOL720\\C[V\\\\ZNDM\"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;721=%y;++y)04<i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\"\"=o,i rav{)y,x(f noitcnuf")"
eval( eval(x) ) yields this string:
"function f(x,y){var i,o="",l=x.length;for(i=0;i<l;i++){if(i<40)y++;y%=127;o+=String.fromCharCode(x.charCodeAt(i)^(y++));}return o;}f("MDNZ\\V[C\027LOV5&))aiq.q;'2?f\001}\014\002\014\013\035\004W\006\037\025\0327\010\013\037\026\025\030\014sqmqpcos&jefP/.{ye~v)I4K:'suzr^oRDOJAWUWG[^MEY\000L_\\\016\034U\013\024\036\003\t\001",40)"
And finally eval( eval( eval(x) ) ) yields the javascript that actually executes:
"document.writeln("info#premiersportfit.com");0;"
Evaluating the last string writes the email address to the DOM and returns 0, terminating the evaluation loop.
I'm not sure if you're trying to reverse engineer something or what, but ideally you just add the necessary code to clear text prior to obfuscation. If you don't have access to that, then you'll have to work out the details of the obfuscator.

Pass multiple parameters from ASP.NET to javascript function

Essentially what I'm trying to do is fairly simple....pass more than one parameter (4 total eventually) into a javascript function from my ASP.NET code behind.
What I've tried to do is this in the ASCX file...
function ToggleReportOptions(filenameText, buttonText) { /*stuff happens here*/ }
and this in the ASCX.cs file...
string testing123 = "testStringOne";
string testing124 = "testStringTwo";
optReportOptionsRunRealTime.Attributes["onClick"] = "ToggleReportOptions('" + testing123 + ", " + testing124 + "')";
optReportOptionsOffline.Attributes["onClick"] = "ToggleReportOptions('" + testing123 + ", " + testing124 + "')";
but this doesn't seem to work as in my output the first variable contains "testStringOne, testStringTwo" and the 2nd variable is "undefined"
Any help on clearing up my probably stupid issue here would be great (i'm very inexperienced with javascript, more of a .NET developer)
You've missed out a few single-quotes, meaning that you're passing a single string containing a comma rather than two separate strings. That is, you're passing 'testStringOne, testStringTwo' rather than 'testStringOne' and 'testStringTwo'.
Try this instead:
optReportOptionsRunRealTime.Attributes["onClick"] =
"ToggleReportOptions('" + testing123 + "', '" + testing124 + "')";
optReportOptionsOffline.Attributes["onClick"] =
"ToggleReportOptions('" + testing123 + "', '" + testing124 + "')";

Categories

Resources