Ok, for reference this is how I did it. Always been very uncomfortable
with async and javascript having come from asp.net. I am writing this
down because...
1. I am surprised with the limited information that exists,
2. In around 24 hours I would have forgotten how to do this....
In dashcode click the edge to edge list and on the first tab select
the dynamic datasource, and add a name in the box below - dashcode
will insert the standard code for List Data Source - in the Library
under code.
I changed this to the following:
var Feed_String = {
_rowData: row_Data1, //populate rowData1 as a Json object on page
load (copied below)
numberOfRows: function() {
return this._rowData.length;
},
prepareRow: function(rowElement, rowIndex, templateElements) {
if (templateElements.label) {
templateElements.label.innerText =
this._rowData[rowIndex].Project_Name;
}
if (templateElements.text8) {
templateElements.text8.innerText =
this._rowData[rowIndex].ProjectID;
}
if (templateElements.text2) {
templateElements.text2.innerText =
this._rowData[rowIndex].Project_Description;
}
var handler = function() {
var jsonItem = templateElements.text8.innerText
var list1 = document.getElementById("list1").object;
var list = document.getElementById("ProjectList").object;
var browser = document.getElementById('browser').object;
var selectedObjects = list1.selectedObjects();
browser.goForward(document.getElementById('listLevel'), "Main
Areas");
localStorage.setItem('selectedProject', jsonItem);
}
rowElement.onclick = handler;
}
Luckily this edge to edge list does not link to the list that follows,
so I did not have to pass a value to the new list (as you can see I
simply stores the value in a localStorage to be used later.
The datasource was created with the following code, and this needs to
be placed in the onload event to make sure its available when you need
it (my only solution to this async stuff - and thanks to a fellow
member).
var rowData1 []; // declare a global variable for the json data
function return_Project_Data()
{
var sqlStringProject = "SELECT ProjectID, Project_Name,
Project_Description FROM About_ProjectMaster"; // like to put the sql
string in a variable
database.transaction(function(transaction) {
transaction.executeSql(sqlStringProject, [],
function(transaction, result) {
for (var i = 0; i < result.rows.length; ++i)
{
var row = result.rows.item(i);
row_Data1.push({Project_Name: row['Project_Name'],
ProjectID: row['ProjectID'], Project_Description:
row['Project_Description']});
}
list1._rowData = row_Data1;
document.getElementById
('list1').object.reloadData();
},
function(transaction, error) {alert(error.message + ' getting
the project list')})
})}
Thats it. Cant believed I wasted so much time searching for a selected
object I was not setting and didn't need!!!
On Nov 20, 10:57 am, Less Obvious <[email protected]> wrote:
> Hi,
>
> After spending two days struggling with Dashcode, I have finally
> created a dynamic JSON datasource from an internal sqlite table, to
> populate an edge to edge list. All works well but, whenever I select a
> row, the code results in the following exception:
>
> SelectedObjects(0) [null] is not an object
>
> This is the code within the rowclick event:
>
> localStorage.setItem('selectedProject',
> (selectedObjects[0].valueForKey("ProjectID")));
>
> The datasource is quite straight forward.
>
> [{ProjectID: "200", Project_Name: "Something",
> Project_Description: "Something else}, ....]
>
> The prepareRow: is as follows:
>
> prepareRow: function(rowElement, rowIndex, templateElements) {
> if (templateElements.text8) {
> templateElements.text8.innerText =
> this._rowData[rowIndex].ProjectID;
> }......
>
> And I have tried setting the value, key etc to text8 without luck...
>
> Now it seems to me that this is a binding issue with the datasource
> but I cannot work out what I need to do with the bindings to make it
> happen. It works fine if there is a static .js file and I use the
> dashcode bindings interface, but what I am missing something
> programatically. Any clues?
>
> Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"iPhoneWebDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/iphonewebdev?hl=en.