Demonstrates using data models with a widget.The only difference when using models in a widget, compared to non-widget use, is that you use Widget.createModel() and Widget.createCollection() methods to create models and collections, respectively. These methods are directly analogous to Alloy.createModel() and Alloy.createCollection(). You can also use the Model and Collection tags in widget views.
The sample defines a widget named alloy.datatable that contains a
<TableView/> and a
<Collection/> element that creates a new Collection instance from the songs.js model file. Each
<TableViewRow/> element is bound to the value of the
info field defined by the songs collection. When a user selects a table row, the view-controller's
handleTableClick method is called.
The widget's view-controller populates the "songs" data collection with data using the Backbone reset() method. The
handleTableClick() function uses the Backbone trigger() method to generate a "rowClick" event that's handled by the main application (see below).
The main application view that contains a
<Widget/> element that includes the alloy.datatable widget.
The main view-controller uses the Backbone on() function to bind a function handler to the "rowClick" event generated by the TableView.