[ALOY-440] Ti.UI.Picker has no collection binding
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-08-21T03:16:58.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.5.0 |
Components | Models, XML |
Labels | qe-manualtest |
Reporter | Tony Lukasavage |
Assignee | Tim Poulsen |
Created | 2012-12-20T17:21:38.000+0000 |
Updated | 2014-08-28T15:15:53.000+0000 |
Description
original discussion
http://developer.appcelerator.com/question/145992/databinding-on-pickerproblem
Collection binding is not implemented for Ti.UI.Picker as it is for Ti.UI.TableView and other generic Titaniums views (View, Window, ScrollView, etc...).solution
Support collection binding on Ti.UI.Picker just as it is on TableView. It will need special handling as the Ti.UI.Picker requires custom parsing for columns and rows. Something like this should be how it would work for devs:
<Alloy>
<Collection src="book" />
<Window class="container">
<Picker dataCollection="book">
<PickerRow title="{title}" />
</Picker>
</Window>
</Alloy>
Attachments
File | Date | Size |
---|---|---|
android_ActualResult_noSpinner.png | 2014-08-14T23:11:01.000+0000 | 40150 |
android_ActualResult_withSpinner_PickerRowBinding.png | 2014-08-14T23:11:01.000+0000 | 40143 |
android_ActualResult_withSpinner.png | 2014-08-14T23:11:01.000+0000 | 38795 |
The original sample doesn't account for columns. Supporting columns could mean any of the following might be expected. What is our goal with this ticket?
PR https://github.com/appcelerator/alloy/pull/483 Test app: https://github.com/skypanther/alloy/blob/ALOY-440/test/apps/testing/ALOY-440 Functional test: build the app, it should display a two-column picker with fruits in the left column and colors in the right. Due to the dataTransform applied, the colors should be in all-caps
I'm not sure where I got the idea that you could use a
**APPROVED**
PR merged
Verified with: Appc Studio - 3.4.0.201408180158 SDK - 3.4.0.v20140819094113 acs - 1.0.16 alloy - 1.5.0-dev npm - 1.3.2 titanium - 3.4.0-dev titanium-code-processor - 1.1.1 OS - mavericks (v10.9.4) Xcode - 6Beta5 Device - iPhone5s(v8.0), Nexus7(v4.4.4) Tested with app (test/apps/testing/ALOY-440) App runS without error and as expected. Able to see the two-column spinner, which is bound to the collections. Hence closing the issue.
See attached sample app 'AlloyPicker_dataCollection.zip'. 1. Run the sample on Android 2. Click on the top ActionBar to add a model from the 'book' collection 3. Click on the Picker Results: 2. Model item is correctly added and displayed in the TableView 3. In the picker, the existing rows are not flushed out each time data is fetched from the collection, therefore adding each time the whole collection items plus one. Reopening. TiSDK 3.4.0.v20140813022514 Appcelerator Studio 3.3.1.201408121314 CLI 3.4.0-dev Alloy 1.5.0-dev
PR https://github.com/appcelerator/alloy/pull/514 Functional review: The pull request includes a new test app, test/apps/testing/ALOY\-440c. Use it or the attached AlloyPicker_dataCollection.zip app. Run it for Android. Click the app's title in the action bar several times, after each click, drop down the picker to see that just as many rows are added to it as to the table.
*APPROVED*
PR merged
Verified as working as expected. Environment: TiSDK 3.4.0.v20140820125714 Appcelerator Studio 3.4.0.201408201526 CLI 3.4.0-dev Alloy 1.5.0-dev Closing.
Is there a problem with doing this in a Widget? I'm using Alloy 1.6.0-dev
StoreLocation
is a model in the widget'smodels/
folder. It uses a syncadapter in the app'slib/alloy/sync
folder and I see the models populated correctly after an initialfetch()
. When the widget loads, before the fetch can be called, I get {color:red}"'null' is not an object (evaluating '$model.__transform')"{color}Binding is supported on the
Thanks! The error is gone. However, when I use my syncadapter, the collection looks full but the picker does not populate. I can only load the Picker by manually adding a model. This reports the correct number of models in the event handler, but the picker remains empty:
This loads the picker correctly with one test entry:
Do I need to do something besides
fetch()
to update the picker?Hmm, the picker should be responding to the same set of events that any other data-bound control would respond to: fetch, reset, delete, etc. Are you using one of the stock sync adapters? Can you post a test app that shows the problem so I can investigate further?
Here is a minimal example of my problem. Thanks for your help. https://github.com/jbeuckm/AlloyWidgetCollectionPicker
What you posted doesn't show create or update methods within your sync adapter. What's triggering the read (fetch) method when you add a model? If you look at https://github.com/viezel/napp.alloy.adapter.restapi/blob/master/restapi.js you'll see that he's triggering fetch as part of the create & update calls.
I call fetch() from the widget's controller here: https://github.com/jbeuckm/AlloyWidgetCollectionPicker/blob/master/app/widgets/CollectionTest/controllers/widget.js#L6 Note that this works with a ScrollableView or TableView but not Picker.