[TIMOB-23215] Windows: Data binding: Using attribute in ListItem that is not in data crashes view
| GitHub Issue | n/a | 
|---|---|
| Type | Bug | 
| Priority | High | 
| Status | Closed | 
| Resolution | Duplicate | 
| Resolution Date | 2016-04-26T14:53:33.000+0000 | 
| Affected Version/s | n/a | 
| Fix Version/s | n/a | 
| Components | Windows | 
| Labels | windows | 
| Reporter | Rene Pot | 
| Assignee | Kota Iguchi | 
| Created | 2016-04-14T16:07:46.000+0000 | 
| Updated | 2017-03-21T23:14:00.000+0000 | 
Description
	I have a ListView with Data Binding set up. I have a transform function attached to the binding of a ListSection. But if my transform function doesn't return data the ListItem expects, it crashes the view/window or throws an error which is unusable (unknown error).
So for example
<ListItem myLabel:text="{labelText}" />
Maybe related to TIMOB23216 but [~topener] could you give us a sample code so we can reproduce the issue on our side?
Hi, the example in the description is already basically what the problem is. Data provided in transform but not used in ListItem is fine, but data to-be-used in the ListItem that is not provided from the transform crashes the view
[~topener] Could you confirm what kind of value
labelTextvariable have? I think you are guessing it was empty or null?The data property was missing. Neither null or empty.
Hmm I can not reproduce this. I think you mean
doTransformreturns object but it doesn't have required property, is that right? For example let say we havedoTransformlike below:function doTransform(model) { return []; }title:<Alloy> <Collection id='info' src="info" /> <Window class="container"> <ListView id="list"> <ListSection id="section" dataCollection="info" dataTransform="doTransform"> <ListItem title="{title}" /> </ListSection> </ListView> </Window> </Alloy>I had troubles with this, but for me it never returned an empty array or object. I guess it should return something like this
function doTransform(model) { return { test: "text", showTitle: false }; }[~topener] Yeah, I tried something like that too but app doesn't crash for me... Now I'm guessing that
doTransformcontains wrong property that causes ListView crash. Could you dump the actual value? Or at least can you provide a property names?function doTransform(model) { Ti.API.info(JSON.stringify(model)); return { test: 'text', showTitle: false }; }Figured it out... turned out to be either
nullorundefined. I was trying toget()a property on a model that didn't exist. Although getting a non-existing property from a model didn't crash anything, trying to insert it in the view did. So that is the actual bug reportGlad to hear you figure it out...Could you provide a simple sample code that reproduce the issue [~topener] ? From what you described, I would imagine like this:
var book = Alloy.createModel('book', {title:'Green Eggs and Ham', author:'Dr. Seuss'}); var unknown_prop = book.get('unknown_prop'); book.save(); // crash??Hi, this has nothing to do with models and saving them. It has to do with DataBinding in a ListView.
function transform(model){ return { text: model.get('unknown_prop') }; }<ListItem myLabel:text="{text}" />I still can't reproduce this but I'm trying in various way. Just in case, which version of alloy are you using? Alloy prior to
1.8.1had a issue around model binding (TIMOB-20577) so make sure you use Alloy1.8.1or1.9.x. (alloy --version)Can confirm, behaves better with 1.8.# and crashes with 1.7.#
Awesome, so you mean crash is fixed in 1.8.x? I think I found a potential workaround for a View crash with alloy on my side...adding
setTimeouton updating model (save) makes View stable for me. I know this is dirty workaround but just in case, hope this works for you too.function updateStatus() { setTimeout(function () { var todo = todos.get(id); todo.set({ done: todo.get("done") ? 0 : 1, date_completed: moment().unix() }).save(); }, 500); }Yeah correct, apologies for that!
Awesome! Resolving this ticket as duplicate of TIMOB-20577.
Closing ticket as duplicate with reference to the above comments and links.