Created
June 21, 2012 12:15
-
-
Save deyles-zz/2965438 to your computer and use it in GitHub Desktop.
JSONDB example showing how to build TableView rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var jsondb = require("com.irlgaming.jsondb"); | |
| var collection = jsondb.factory("test","yoursharedsecrethere"); | |
| // grab all records with a value of greater than or equal to 10 for the attribute "i" | |
| // with a limit of 200 | |
| var o = collection.find({i:{$gte:10}, {limit:200}); | |
| // tuples in the result look something like: | |
| /* | |
| { | |
| title: 'foo', | |
| description: 'bar' | |
| } | |
| */ | |
| // instantiate the table view | |
| var table = Ti.UI.createTableView({ | |
| width: 320, | |
| height: 480, | |
| top:0, | |
| left:0 | |
| }); | |
| // the data container array for the table rows | |
| var data = []; | |
| // iterate through the results and build the table | |
| o.forEach(function(tuple) { | |
| var row = Ti.UI.createTableViewRow({ | |
| height:50, | |
| width:320 | |
| }); | |
| row.add(Ti.UI.createLabel({ | |
| text:tuple.title, | |
| height:20, | |
| width:320, | |
| top:0, | |
| left:0 | |
| })); | |
| row.add(Ti.UI.createLabel({ | |
| text:tuple.description, | |
| height:30, | |
| width:320, | |
| top:20, | |
| left:0 | |
| })); | |
| data.push(row); | |
| }); | |
| table.setData(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment