After my first steps with SB I ran into an issue: I try to fill an ListIconGadet by reading JSON-Data from a PHP-Script. What happend is, that the data appears only after the second click on the Test-Button!
Could anyone give a hint to solve the problem?
Lars
Attantion: SB and demo.php only work if they are running on a web-server.
demo.php
Code: Select all
<?php
$array = array( "Peter"=>"35",
"Ben"=>"37",
"Joe"=>"43");
echo json_encode($array);
?>
Code: Select all
Global Window_0
Global lb_job,demobutton
Global NewMap jsonValues.s()
Procedure get_json(Success, Result$)
Protected i,jj
ClearMap(jsonValues())
If Success
jj=ParseJSON(#PB_Any, Result$)
If jj
ExtractJSONMap(JSONValue(jj), jsonValues())
FreeJSON(jj)
EndIf
Else
; Debug "HTTPRequest(): Error"
EndIf
EndProcedure
Procedure GadgetEvents()
eg=EventGadget()
et=EventType()
Select eg
Case demobutton
HTTPRequest(#PB_HTTP_Get, "demo.php", "", @get_json())
ClearGadgetItems(lb_job)
ForEach jsonValues()
AddGadgetItem(lb_job,-1,Str(r)+#LF$+MapKey(jsonValues()) + #LF$ + jsonValues())
r+1
Next
EndSelect
EndProcedure
Window_0 = OpenWindow(#PB_Any, x, y, 600, 400, "demo", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_WindowCentered)
lb_job = ListIconGadget(#PB_Any, 5, 50, 520, 330, "Column 1", 100)
demobutton = ButtonGadget(#PB_Any, 5, 8, 80, 30, "TEST")
RemoveGadgetColumn(lb_job,0)
AddGadgetColumn(lb_job, 0, "id",0) ; is not 0!
AddGadgetColumn(lb_job, 1, "Name",80)
AddGadgetColumn(lb_job, 2, "Age",20)
BindEvent(#PB_Event_Gadget,@GadgetEvents())