#1 2016-07-19 04:44:51

reg4app
Member
Registered: 2016-05-16
Posts: 147

Can select control contain name:value pairs

i want to show a string in select control and when user select one item,will get another value to store to database,just like

select control list name string A      and there are corresponding value to get  like 1
                                         B                                                                   2
                                         C                                                                   3
                                         D                                                                   4


therefore ,i can get both name string and the key value ,and save to the database...


Joshua.Y

Offline

#2 2016-07-19 09:29:26

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Can select control contain name:value pairs

Hello Joshua,

I perfectly understand what you wanted, and, certainly, the HTML Select control allow us to put a "visible" value and a non visible one, that is, we can show to the user the string "A", but the Select's option (item) can have associated a value of "1", other number or other string.

Said that, App Builder doesn't work in the same way with the Select control, then we can't think in the above solution, but a possible workaround to get what we wanted. Remember we can deal with "normal" variables, "Array" variables  and "Object" variables.

Maybe we can use some approach like if receive an object (maybe a JSON response) with pairs of keys and values, and then use the keys to feed the Select control. Then, when the Select changes we can iterate over the object variable to get the value of the key.

I think we can do that and maybe in others way too, so I want to ask you now, how you receive the key/values pairs? How you feed the Select control right now?

Offline

#3 2016-07-20 03:26:29

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: Can select control contain name:value pairs

Thanks for the clue

Yes, data is array of  JSON object

follow your suggestion,I work it through , see below :

a HttpClient1, set url to the JSON array url

in Success event

SetVar "[i]" "0" "Number"

ArrayLength "HttpClient1.Response" "Data4SelectLen"


While "[i]" "<=" "[Data4SelectLen-1]"
  
  ArrayGetItem "HttpClient1.Response" "[i]" "Data4Select"
  ArrayPush "[Select1.Items]" "[Data4Select.Dist]"
  SetVar "[i]" "[i]+1" "Number"
EndWhile

This is to fill the Select control

in a button's click event

SetVar "[i]" "0" "Number"

ArrayGetItem "[Select1.Items]" "[Select1.ItemIndex]" "TmpString"

While "[i]" "<=" "[Data4SelectLen-1]"

  ArrayGetItem "HttpClient1.Response" "[i]" "Data4Select"

  If "[Data4Select.Dist]" "==" "[TmpString]"
  SetVar "KeyValue" "[Data4Select.id]" "Number"
  AlertBox "[KeyValue]" "info"
  Break
  EndIf

  SetVar "[i]" "[i]+1" "Number"
EndWhile

this can work,but seems a lot of coding....
and by the way ,Is that a way to store the 'HttpClient1.Response' into variable??


Joshua.Y

Offline

#4 2016-07-20 10:20:36

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Can select control contain name:value pairs

Hello Joshua,

Don't appear lot of code to me, and after all they have their sense and logic. The only think I see is something like this:

[Data4SelectLen-1]

This can be work, but, I think not recommended. A better approach can be one of these:

Dec "[Data4SelectLen]"
SetVar  "[Data4SelectLen]" "[Data4SelectLen]-1"

About the "Response" of an HTTP Client control, if we are talking about a JSON response, then we can access that object directly using the "Response" variable, without any other thing to do before. You can take a look at some of the "JSON*" included app samples.

Please, Joshua, post here any further question you have.

Offline

#5 2016-07-20 10:56:18

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: Can select control contain name:value pairs

Thanks ,I get it
just another question
when i test the sample ,even i just changed a label's Text,I had to delete the '_Compiled'  folder to make the changes take effect...
and of course,i save the project before run.


Joshua.Y

Offline

#6 2016-07-20 11:01:00

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: Can select control contain name:value pairs

OH,I find a way ,after change anything ,First 'Build' (F8),then run,and everything become OK
smile


Joshua.Y

Offline

#7 2016-07-20 11:25:48

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Can select control contain name:value pairs

Hello Joshua,

Just for your information about the "Build", "Debug" and "Run" commands:

Build (F8) - This command build the application, but no save it before. This command is intented when want to deploy our application, that is, we debug it previously, save the latest changes and then we are ready to deploy so we use the "Build" command. The "Build" do not include debug information in the application, which is good to enter in production.

Run (CTRL + F9) - This command run the latest app's build available. They build the app (without save it first and without include debug information) if a previously build is not found. This command is intented to be use when we want to launch the latest build quick and fast, since this command don't save the app nor build it (if found an existing build) but just launch the latest build available.

Debug (F9) - This command save the application changes if any, then build the application including debug information on it, and finally launch the application into the integrated debugger. This command is intented to use when we are working on the application, and just want to debug it to review the latest changes, etc.

---

This last (Debug) is the prefered command when work in the application, since they include debug information in the application and additionally the Debug command doesnt' write manifests files for our applications nor other stuff which is not required to debug the application into the integrated debugger. So this is another point to use the "Build" (F8) command when we want to deploy our application: the "Build" command yes write manifests, prepare icons, splash screens, config files and other stuff.

So in conclusion:

1º Use the Debug (F9) command when work in the application. Additionally use the "Run" (CTRL+F9) when you only want to launch the latest build/debug.

2º Use the Build (F8) when you are ready with your application and want the files you need in order to deploy it into your desired platforms.

Hope this information can help you Joshua. smile

Offline

#8 2016-07-21 06:13:55

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: Can select control contain name:value pairs

Your explaination is clear enough! smile
and I want to know if one view's content can be access from another view,like the "Response" of an HTTP Client control...,and so on


Joshua.Y

Offline

#9 2016-07-21 10:15:16

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Can select control contain name:value pairs

Hello Joshua,

About this last question, I think you can access the "Response" variable. You must try it.

P.S. Please, put every new question in a new forum's thread. smile

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.