B4J Question [BANano] [SOLVED] How to manipulate objects and then some HTML data attribute link?

Mashiane

Expert
Licensed User
Longtime User
Ola

Assuming you have this code defined?

B4X:
#if javascript
var dataObj = {
"records":[
{"CustomerName":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
{"CustomerName":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Around the Horn","City":"London","Country":"UK"},
{"CustomerName":"B's Beverages","City":"London","Country":"UK"},
{"CustomerName":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
{"CustomerName":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
{"CustomerName":"Blondel père et fils","City":"Strasbourg","Country":"France"},
{"CustomerName":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
{"CustomerName":"Bon app'","City":"Marseille","Country":"France"},
{"CustomerName":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
{"CustomerName":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
{"CustomerName":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
{"CustomerName":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
{"CustomerName":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
]};

Q1: How can you get the dataObject via BANano without having to write an additional function like

B4X:
function getDataObject () {
    return dataObj;
};

Assuming that you want to access and perform some CRUD on the object?

I've tried..

B4X:
Dim dataObject As BANanoObject = BANano.Eval("return dataObj;")

It returns and illegal return statement?

Q2: If I define my object directly via code, how do I assign it to an html data attribute? For example.

B4X:
Dim dataObj As Map = CreateMap()
dim records As List
records.Initialize
records.Add(CreateMap("CustomerName": "Alfreds Futterkiste", "City": "Berlin", "Country": "Germany"))
records.Add(CreateMap("CustomerName": "Ana Trujillo Emparedados y helados",    "City": "México D.F.", "Country": "Mexico"))
records.Add(CreateMap("CustomerName": "Antonio Moreno Taquería", "City": "México D.F.", "Country": "Mexico"))
dataObject.Put("records", records)

In HTML...

B4X:
<div data-anele="dataObj"></div>

I understand that BANano returns _dataobj globally or this is the wrong name?, is it possible to assign the object defined via code to an HTML data attribute?

Q3: The same applies for subs.

B4X:
Sub myControllerCode(xxx as string)
Do_1_2_3
End Sub

How do I

B4X:
<table controller="myControllerCode">

I understand that perhaps I need to define a callback with or maybe not.

B4X:
Dim xxx as object
Dim cb as BananoObject = BANano.CallBack(Me, "myControllerCode", array(xxx))

But how do I get the html to know that we have a banano sub named "myControllerCode"?

Thanks.
 

alwaysbusy

Expert
Licensed User
Longtime User
Q1 is simple:
B4X:
Dim dataObject As BANanoObject
dataObject.Initialize("dataObj")
Log(dataObject)

As for Q2 and Q3: never seen such constructions. As far as I'm aware a data- attribute can only hold a String (can be an URL safe json representation of an object), never an object itself. Controller is an unkwown attribute for me too.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Thanks, Q1 is really easy. Now I know.

As far as I'm aware a data- attribute can only hold a String

The "controller" attribute was just an example, it can be anything. So I need to get the "string" name of my sub.

So that means I need to know the BANAno string name for my sub. How does one get that?

Project - anelex
Module - aneley
Sub - anelez

Does it mean it should be "banano_anelex_aneley_anelez" or something, for example, if one would use .GetFunction("anelez")?

#ThinkingAloud.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…