Hi all,
Hope somebody has come across this before.
I have a web app built using dashcode that connects to a web service and fetches data via json, which is then used to create a list in a stacklayout.
So, each item in the list (they are restaurant reviews) has the title of the review, and when clicked, the stacklayout changes view to the review details. All that works well.
Where I am stuck is when no reviews exist, i.e. an empty list is being returned from the web service, or at least a list with no values. The view with the list on just contains the back button and no labels, as you'd expect.
I want to check if the list is empty and just alert or display a message to that effect.
This is the onclick event which changes datasource and retrieves the list of reviews:
As I say, all that works fine, only when the list is empty all I get is an empty page. What I need is:
Can anybody help as I have run out of ideas...?
Thank you very much in advance.
----------
To be a little more succinct, all I really need is a way to test the value of the label on the list, because if the webservice query returns no results I can return a value, say 'No Reviews' and have that appear as a single item list.
The label of the list, reviewNameLabel, is linked to the datasource but every time I try to reference it as a var to test it's value I get the 'object is null' error. i.e. reviewNameLabel doesn't exist as an element.
How can I reference and check reviewNameLabel's value?
Hope somebody has come across this before.
I have a web app built using dashcode that connects to a web service and fetches data via json, which is then used to create a list in a stacklayout.
So, each item in the list (they are restaurant reviews) has the title of the review, and when clicked, the stacklayout changes view to the review details. All that works well.
Where I am stuck is when no reviews exist, i.e. an empty list is being returned from the web service, or at least a list with no values. The view with the list on just contains the back button and no labels, as you'd expect.
I want to check if the list is empty and just alert or display a message to that effect.
This is the onclick event which changes datasource and retrieves the list of reviews:
Code:
function gotoReviewsView(event)
{
var textFieldValue = document.getElementById("listingID");
var dataSource = dashcode.getDataSource("reviews");
reviewID = textFieldValue.value;
searchString="http://mywebservice/wservice/ws_json_r.php?format=json&reviewid="+reviewID;
dataSource.setValueForKeyPath(searchString, "url");
// Datasource changed - now change view
var stackLayout = document.getElementById('stackLayout').object;
stackLayout.setCurrentView('reviewsView');
}
As I say, all that works fine, only when the list is empty all I get is an empty page. What I need is:
Code:
// Datasource changed - now change view
var stackLayout = document.getElementById('stackLayout').object;
stackLayout.setCurrentView('reviewsView');
[COLOR="Red"]if list is empty or null {
// display something
}[/COLOR]
}
Can anybody help as I have run out of ideas...?
Thank you very much in advance.
----------
To be a little more succinct, all I really need is a way to test the value of the label on the list, because if the webservice query returns no results I can return a value, say 'No Reviews' and have that appear as a single item list.
The label of the list, reviewNameLabel, is linked to the datasource but every time I try to reference it as a var to test it's value I get the 'object is null' error. i.e. reviewNameLabel doesn't exist as an element.
How can I reference and check reviewNameLabel's value?