Page 1 of 1

Display method & example

Posted: Mon Oct 25, 2010 8:38 pm
by Front
Hi, there
I created a method in JadeScript to display the information of product and brand together.
Now I have two classes, product and brand.
I want to have a display method to show me the price and weight from product class, trademark and grade from brand class.
What code I should use?????
I can't find any example from the internet!
Thanks for helping!!! ^^

Re: Display method & example

Posted: Tue Oct 26, 2010 7:46 am
by Jade Support
Hello Front,

Thanks for your question. I've put together a very simple example schema (attached to this forum posting) that should allow you to see how this is achieved. Download both the ProductExampleSchema.scm and ProductExampleSchema.ddb files and together load them in to the JADE system you're using. They'll create a new schema called "ProductExampleSchema".

There are two JadeScript methods within the schema; createTestData() and getData(). The latter of which is shown below:

Code: Select all

getData() protected; vars root : Root; product : Product; brand : Brand; begin // Setup the Root object so we can access it's local collection // of Brands... root := Root.firstInstance; if root = null then write "Error: Root object is null, aborting."; return; endif; // Iterate each Brand object and then each Product within that // Brand's collection of Products... foreach brand in root.allBrands do foreach product in brand.allProducts do // Display the Product information... write "Name: " & product.name; write "Price: $" & product.price.String; write "Weight: " & product.weight.String & "g"; write "Brand Name: " & brand.name; write "Brand Trademark: " & brand.trademark; write "Brand Grade: " & brand.grade.String; write Cr; endforeach; endforeach; end;
If you first execute createTestData(), then getData() the following information will be output:
Name: Sliced Peaches
Price: $2.99
Weight: 300g
Brand Name: Store Brand
Brand Trademark: Store Brand Limited
Brand Grade: C


Name: Sliced Peaches
Price: $3.69
Weight: 300g
Brand Name: Watties
Brand Trademark: Watties Limited
Brand Grade: A
It's a very simple example but should show you how to store and retrieve persistent data in a JADE database using MemberKeyDictionary collections and a singleton 'Root' object.

Regards,