Smartface define a global variable and usage - smartface.io

I want to send json data or a variable to Page2 from Page1. My codes as follows. I guess I writing wrong code. I don't know how to do this.
Page1:
var value1="test";
var jsonData=[];
jsonData.push("Value1");
jsonData.push("Value2");
jsonData.push("Value3");
Page2
var TextBox = new SMF.UI.EditBox({
width:"88%",
height:"100%",
left:"22%",
top:"0%",
text:"",
});
TextBox.text = Pages.Page1.value1;
TextBox.text = Pages.Page1.jsonData;
Pages.Page1.add(TextBox);

You could just add that variable to the Global file and then use it where you wish. Like:
//Global.js
var myVar;
//Page1.js
Label.text = myVar;
//or even change its value
myVar = "Hello";
But I am looking for a way of doing this without declaring a global variable too.

Related

Flutter pass a value to a global variable

i am using flutter and stackoverflow for the first time, forgive me errors.
I have global variables in a global.dart file.
In my main I want to access and edit a variable by passing it the value
Global.dart
String nome_impianto1 = "IMPIANTO 1";
String nome_impianto2 = "IMPIANTO 2";
String nome_impianto3 = "IMPIANTO 3";
String nome_impianto4 = "IMPIANTO 4";
main.dart
import 'package:services/global.dart' as globals;
globals.nome_impianto1 = usrcontroller_ovrelay_impianto.text; //so it works.
how can I pass the value I want to change?
globals.nome_impianto{$'1'} = usrcontroller_ovrelay_impianto.text //I know it doesn't work, and just to get the idea;
thank to all
Best regards
Andrea
Avoid using global variables in flutter. If you are managing state gloabally use StatefulWidget and even better start using provider or even more advanced bloc.
For your question, if you want to access these globally it is better to use a Map
// Global.dart
Map<String, String> globals = {
"nome_impianto1": "IMPIANTO 1",
"nome_impianto2": "IMPIANTO 2",
"nome_impianto3": "IMPIANTO 3",
"nome_impianto4": "IMPIANTO 4",
};
// main.dart
int index = 1;
globals["nome_impianto$index"] = usrcontroller_ovrelay_impianto.text;
flutter doesn't have reflection https://stackoverflow.com/a/49871692/8608146
Add this to any of your function:
setState((){
globals.nome_impianto1 = usrcontroller_ovrelay_impianto.text;
});

want to store promise value in an array

I want to get all the values from a registration page and store all values in an array. How can I do that in protractor?
var arr = new Array(); //declare array
InputName.getAttribute("value")
.then(function(value){
arr[0]=value; // want to store promise value in an array
});
console.log(arr[0]);
If you run your code, it will first log arr[0] and then resolve Promise. Therefore, you may access that array's values in the next Promise. Something like this
var arr = new Array(); // <- this is by the way bad practice, use 'let arr = [];'
InputName.getAttribute("value")
.then(function(value) {
arr[0]=value; // I would use arr.push(value)
});
anotherInput.getAttribute("value")
.then(function(value) {
console.log(arr[0]); // your value should be accessible here
arr.push(value) // push another value
});
But, honestly, I've been working with Protractor fo a while now and I still have difficulties understanding promises... This why I'm using async/await in my tests so if I were to implement something like that I would end up having the following
let arr = [];
let value1 = await InputName.getAttribute("value");
arr.push(value1);
console.log(arr[0]);
Clear, neat code with no hustle. Plus protractor team is actually removing promise_manager, so one day when you update it your code will not work anymore. Then why not switch earlier

Setting and getting model values in OpenUI5

I am trying to play with OpenUi5. I want to set 'artificial model' change the value and print it.
My code:
onInit: function () {
this.getView().setModel(new sap.ui.model.json.JSONModel());
this.getView().getModel().setData({"name":"Jon"});
this.getView().getModel().setProperty("name", "Ann");
var name = this.getView().getModel().getProperty("name");
window.alert(name);
It says that name is null.
Why is that so?
you might want to look into this tutorial from SAP:
https://sapui5.hana.ondemand.com/1.54.8/#/topic/e5310932a71f42daa41f3a6143efca9c
but for a quick answer:
you are missing a /, and you dont need the " in you json
this.getView().getModel().setData({name:"Jon"});
...
var name = this.getView().getModel().getProperty("/name");
obv same for the set property line
also for easier readability of you code i'd do smth in the lines of:
onInit: function () {
var oYourModel = new JSONModel({
name: "Jon"
});
this.getView().setModel(oYourModel, "modelName");
this.getView().getModel("modelName").setProperty("/name", "Ann");
var name = this.getView().getModel().getProperty("/name");
window.alert(name);

Swift: Indirect access / mutable

I need to go to a referenced structure:
class SearchKnot {
var isWord : Bool = false
var text : String = ""
var toNext = Dictionary<String,SearchKnot>()
}
When inserting, I need to update values in toNext dictionary. Because I want to avoid recursion, I do it in a loop. But there I need a variable which jumps from one toNext item to the other, able to change it.
var knots = toNext
...
let newKnot = SearchKnot()
knots[s] = newKnot
The last command only changes a local copy, but I need the original to be changed. I need an indirect access. In C I would use *p where I defined it as &toNext. But in Swift?
I found a solution. I remembered old pascal days. ;-)
I don't use the last reference, but the second last. Instead of
knots[s]
I use
p.knots[s]
For hopping to the next knot, I also use
p = p.knots[s]
and could use
p.knots[s]
again. Also p.knots[s] = newKnot works, because p is local not the entire term.

as3 - loop over all text fields?

I have a form in as3 flash with textfields and radio buttons with their "instance name" all set consecutively such as:
field_1
field_2
field_3
...etc
Is there an easy way in AS3 code to loop over all those fields and get their values in an array? Ideally I'd like a simply loop to get the values (so I can add in a simple popup if a value is missing) and then with the filled array simply post it using URLRequest.
Thanks!
If you want a way that's a little less work and more maintainable (if the amount of text can change in the future or you need to reuse the code on other forms or don't want to bother with instance names), then you could do something like the code below.
Keep in mind this assumes all your text fields are children of the same parent and is in the scope of that parent (so on a frame in the timeline that holds all your text fields)
function validateTextFields(){
var tmpTf:TextField;
var i:int = numChildren;
while(i--){ //iterate through all the display objects on this timeline
tmpTf = getChildAt(i) as TextField;
if(tmpTf){
//now that you have the textfield, you can check for an appropriate value, or send the value to a server, or store it in an array etc.
//check if the value is blank, if so set the background to red
if(tmpTf.text == ""){
tmpTf.background = true;
tmpTf.backgroundColor = 0xFF0000;
}else{
tmpTf.background = false;
}
}
}
}
It sounds like you want to use a for statement. I've also used a multi-dimensional array to store the instance names, and the text that they contain. I like to use the variable _path to define the scope of my code.
var _path = this;
var text_ar:Array = new Array(['instance_1',''],['instance_2',''],['instance_3','']); //instance name, instance text.
for(var i=0; i<ar.length; i++)
{
text_ar[i][1] = _path[text_ar[i][0]].text
}
trace( text_ar[1][1] ); //Traces the text that's entered in instance_1.