B4J Question [SOLVED] [BANanoVuetifyAD3] How to convert query string to List

VittorioBarile

Member
Licensed User
B4X:
Sub GetAllSetup
    'clear content
    setup.SetData("records", "")
    Dim dbMySQLE As BANanoMySQLE
    dbMySQLE.Initialize("test", "setup_standard", "id_setup", "id_setup")
    dbMySQLE.SelectDistinctAll(Array("codice"), Array("codice"))
 
    dbMySQLE.JSON = banano.CallInlinePHPWait(dbMySQLE.MethodName, dbMySQLE.Build)
    dbMySQLE.FromJSON
    Select Case dbMySQLE.OK
        Case False
            Dim strError As String = dbMySQLE.Error
            vuetify.ShowSnackBarError("An error took place whilst running the command. " & strError)
            Return
        Case Else
            vuetify.ShowSnackBarSuccess("Query corretta")
    End Select
    'convert to json
 
    Dim jsonSetup As String = banano.ToJson(dbMySQLE.result)
 
    mappaDeiSetup = banano.ToJson(dbMySQLE.result)
    setup.SetData("records", jsonSetup)
End Sub

how could I put in a Vue List?

this is the result of jsonSetup: [{"codice":"custom_1"},{"codice":"custom_2"},{"codice":"custom_3"},{"codice":"custom_4"},{"codice":"custom_5"},{"codice":"default_1"},{"codice":"default_10"},{"codice":"default_2"},{"codice":"default_3"},{"codice":"default_4"},{"codice":"default_5"},{"codice":"default_6"},{"codice":"default_7"},{"codice":"default_8"},{"codice":"default_9"}]

i want something like this for all elements of jsonSetup as Map

B4X:
    list6.ClearItems
    list6.AddItemParentChild("", "1", "mdi-ticket", "red", "Attractions", "")
    list6.AddItemParentChild("1", "c1", "", "", "List Item", "")

how could i make it in a iterable cycle?
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Hi

For each record in the list you just need to know the parent and then the child field.

This structure only has one field per record, so it’s impossible.

B4X:
{"codice":"custom_1"},{"codice":"custom_2"},{"codice":"custom_3"},{"codice":"custom_4"},{"codice":"custom_5"},{"codice":"default_1"},{"codice":"default_10"},{"codice":"default_2"},{"codice":"default_3"},{"codice":"default_4"},{"codice":"default_5"},{"codice":"default_6"},{"codice":"default_7"},{"codice":"default_8"},{"codice":"default_9"}][/code
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
Hi

we want something like this from list :
B4X:
list3.ClearItems
    list3.AddItemHeader("codice")
    list3.AddItemDivider(True)
    list3.AddItemLeftCheckBox("1", True, "custom_1", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("2", True, "custom_2", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("3", True, "custom_3", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("4", True, "custom_4", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("5", True, "custom_5", "", "", "", "mdi-delete", "red", 0, "")
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Remember, the result of your query returns a collection of maps inside a list (i.e array), you need to loop through the list and then manipulate the records as you wish.

For example

B4X:
For each rec As Map In dbMySQLE.Result
dim scodice as string = rec.get("codice")
list3.AddItemLeftCheckBox(... , scodice, ...)
Next

Its that simple.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Just for clarity:

The original question is about generating a structure like this from the provided data. That is impossible with the example code provided as parent child relationships are not provided.



This above, was generated by this code:

B4X:
Sub BuildList6
    'inject a list
    Dim list6 As VueElement = vuetify.AddList(Me, vlists.MatrixID(3, 2), "list6", True, True, True, Null)
    lists.BindVueElement(list6)
   
    'initialize the listview options, we use the default options
    'to source the data
    Dim list6Options As ListViewItemOptions = vuetify.NewListViewItemOptions
    'set the data source of the list items
    list6Options.dataSource = "topics"
    'add the group template to the list
    Dim list6Template As VueElement = vuetify.AddListViewGroupTemplate(Me, "list6", 0, list6Options)
    'bind the template
    lists.BindVueElement(list6Template)
    '
    list6.ClearItems
    list6.AddItemParentChild("", "1", "mdi-ticket", "red", "Attractions", "")
    list6.AddItemParentChild("1", "c1", "", "", "List Item", "")
    list6.AddItemParentChild("", "2", "mdi-silverware-fork-knife", "green", "Dining", "")
    list6.AddItemParentChild("2", "c3", "mdi-cog", "red", "Breakfasy & brunch", "")
    list6.AddItemParentChild("2", "c4", "mdi-cog", "green", "New American", "")
    list6.AddItemParentChild("2", "c5", "mdi-cog", "orange", "Sushi", "")
    list6.AddItemParentChild("", "3", "mdi-school", "pink", "Education", "")
    list6.AddItemParentChild("3", "c6", "", "", "List Item", "")
    list6.AddItemParentChild("", "4", "mdi-run", "", "Family", "")
    list6.AddItemParentChild("4", "c7", "", "", "List Item", "")
    list6.AddItemParentChild("", "5", "mdi-bottle-tonic-plus", "", "Health", "")
    list6.AddItemParentChild("5", "c8", "", "", "List Item", "")
    list6.AddItemParentChild("", "6", "mdi-content-cut", "", "Office", "")
    list6.AddItemParentChild("6", "c9", "", "", "List Item", "")
    list6.AddItemParentChild("", "7", "mdi-tag", "", "Promotions", "")
    list6.AddItemParentChild("7", "c10", "", "", "List Item", "")
    '
    Dim listTree As List = list6.ListViewToTree
    lists.SetData("topics", listTree)
End Sub

The follow up question is requesting for a structure like this.



This here was generated by this code...

B4X:
Sub BuildList3
    'inject a list
    Dim list3 As VueElement = vuetify.AddList(Me, vlists.MatrixID(2, 1), "list3", True, True, True, Null)
    lists.BindVueElement(list3)
   
    'initialize the listview options, we use the default options
    'to source the data
    Dim list3Options As ListViewItemOptions = vuetify.NewListViewItemOptions
    'set the data source of the list items
    list3Options.dataSource = "tasks"
    list3Options.showleftcheckboxes = True
    'add the template to the list
    Dim list3Template As VueElement = vuetify.AddListViewTemplate(Me, "list3", 0, list3Options)
    'bind the template
    lists.BindVueElement(list3Template)
    '
    list3.ClearItems
    list3.AddItemHeader("Tasks")
    list3.AddItemDivider(True)
    list3.AddItemLeftCheckBox("1", True, "Buy 10 Bananas", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("2", True, "Eat 2 Bananas", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("3", True, "Count Bananas", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("4", True, "Monkey stole 1 Bananas", "", "", "", "mdi-delete", "red", 0, "")
    list3.AddItemLeftCheckBox("5", False, "Poo 2 Bananas", "", "", "", "mdi-delete", "red", 0, "")
    '
    lists.SetData("tasks", list3.Records)
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…