Tired of ListDataItems’ idiosincratic format? Do you want to write your data binding directly in the templates? Fear no more! Mighty Morphing Power Templates are here for you!
With gitTio for Titanium SDK you can easily install it with
$ gittio install power-templates
To download the module for manual install (e.g. through Appcelerator Studio) then head over the releases page to download the latest packaged module.
With npm for Node.js and io.js you can easily install it as a dependency for another package with
$ npm install --save power-templates
<ListView id="list" module="power-templates">
<Templates>
<!-- use [ expression here ] for property parsing! -->
<ItemTemplate name="simple" itemId="[ id ]">
<Label text="[ name ]" />
</ItemTemplate>
</Templates>
<ListSection id="section"/>
</ListView>
$.section.items = [
// automatic model ➜ ListDataItem!
$.list.powerTemplates.simple.parse({
id: 12,
name: 'Example'
})
];
var section = Ti.UI.createListSection({});
var list = require('power-templates').createListView({
templates: {
"simple": {
properties: {
// use functions for property evaluation!
itemId: function (model) { return model.id },
},
childTemplates: [
{
type: 'Ti.UI.Label',
properties: {
// or the [expr] form!
text: '[ name ]'
}
}
]
}
},
sections: [ section ]
});
section.items = [
// automatic model ➜ ListDataItem!
list.powerTemplates.simple.parse({
id: 12,
name: 'Example'
})
];
Want to contribute? Yes please! Here’s our wishlist:
- implement alternative ListSection APIs
- implement
itemId
-based ListSection APIs (instead of indexes) - implement a ListView-less parsing (a-la React/Angular)
Humbly made by the spry ladies and gents at SMC.
This library, power-templates, is free software ("Licensed Software"); you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA