06-28-2012 03:33 PM
I have found that using the variable "ListItemData" when ListItem.initialized is still false, sometimes yields the following error message:
TypeError: Result of expression 'ListItemData' [undefined] is not an object
For example in my context,
will generate the error. If I change the code to this:
text: itemRoot.ListItem.initialized ? ListItemData.message : ""
No error message is produced.
Has anyone else encountered cases like this?
It seems a bit cumbersome to add the initialized condition to all expressions that use ListItemData and I'm sure that is not the intention of the designers of the ListView control. Should we simply ignore the runtime error?
It's a bit difficult to post my entire context here. I'm just curious if anyone else has encountered this.
07-04-2012 03:11 PM
Can you post more detail? e.g. http://supportforums.blackberry.com/t5/Cascades-De
ListItemData is also used by samples cascadescookbookqml, quotes, stampcollector, and weatherguesser. Are you able to reproduce this issue with them? If not, I'd like to understand how yours differs.
07-16-2012 09:59 AM
It took a while, but I succeeded in building a small app, which reproduces the issue.
Please see the attached.
07-17-2012 04:11 PM
Interesting. Still looking at this.
A few comments:
- the routine is called before the error is displayed...
- ...even if the routine returns false
If you're just trying to filter out some objects, you might be better off filtering the data in your data model, or in a data model that filters your data model, as in:
07-17-2012 04:51 PM
First of all, I'm glad the code reproduced the issue for you. That's usually 80% of the battle...
I also saw that the method gets called before the error and then a second time after the error.
I believe that the first time it is being called, ListItem.initialized is still false (hence the error, yet on the other hand it seems to have the object on which to invoke the method). The second call is made after the ListItem is fully initialized.
Indeed when changing the QML line to:
visible: itemRoot.ListItem.initialized ? ListItemData.doItAvailable("getit") : false
The call is only made once.
In regard to your question, the use case is not one of filtering the data, rather which UI elements should be shown for a given list item.
Anyhow, glad you're on the case... Good luck!
07-18-2012 10:59 AM
I can't say I'm overly surprised at the behaviour you see. Changing the visible flag of something in a list during creation falls in my mind under the umbrella of changing the layout of the UI while constructing the layout. Nevertheless, I agree it feels a bit odd in this case.
I think the following is the clearest way to code what you want, and avoids unnecessary calls:
text: "Hello 2"
//The following line produces this error:
//TypeError: Result of expression 'ListItemData.doItAvailable' [undefined] is not a function.
//The following is a variation, which prevents the error.
//As such, it seems that 'ListItemData' is being used prematurely.
//visible: itemRoot.ListItem.initialized ? ListItemData.doItAvailable("getit") : false
visible = ListItemData.doItAvailable("getit");
07-19-2012 03:40 AM
I don't think this is a specific problem with the 'visible' property.
If remove the visible property altogether and replace the text property binding with this:
text: ListItemData.doItAvailable("getit") ? "Red" : "Green"
The same error message will also appear.
My hunch is that the error has to do with the fact that doItAvailable is a method and not a property. From other playing, I have seen that when using non-NOTIFYable properties, warnings are issued. A method is definitely non-NOTIFYable, so this might be similar.
The reason for using a method and not a property in the first place was the ability to pass parameters. Properties with parameters seem not to be supported.
It might simply be the case that the framework is only fully happy when QML properties are bound to NOTIFYable C++ properties. Although, I have not seen any documentation in this regard. Furthermore, it might only be an issue with the ListView control.
As for using onCreationCompleted, please see my post here:
07-26-2012 03:34 PM
Thanks for the tip.
Actually, I don't mind using the workaround, which I posted at the beginning of this thread.
I mainly posted this, so you guys could take a look and see if things are working as they should be.