Skip to content

Instantly share code, notes, and snippets.

@yomybaby
Created September 18, 2015 12:47
Show Gist options
  • Save yomybaby/154a2755cf70bda03dd2 to your computer and use it in GitHub Desktop.
Save yomybaby/154a2755cf70bda03dd2 to your computer and use it in GitHub Desktop.
Titanium : AttributedString in ListItem with link event.

Yes, you can do that in Titanium.

screenshot

var html2as = require('nl.fokkezb.html2as');
function onClickLink(e){
alert(e.url);
}
var contents = [
'Korean Community <a href="wow">http://tidev.kr</a>',
'Yo Studio : <a href="http://yostudio.kr">http://yostudio.kr</a>'
];
var items = [];
_.each(contents,function(c){
var attStr;
html2as(c,function(err, as){
if(!err){
attStr = as;
}
});
items.push({
template : 'myItem',
content : {
attributedString : attStr
}
})
});
$.section.items = items;
$.index.open();
<Alloy>
<Window class="container">
<ListView>
<Templates>
<ItemTemplate name="myItem">
<Label class="contentLabel" bindId="content" onLink="onClickLink"></Label>
</ItemTemplate>
</Templates>
<ListSection id="section">
</ListSection>
</ListView>
<Label/>
</Window>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment