Last active
May 27, 2016 16:41
-
-
Save DouglasHennrich/9dd2f2a5e104d2ae3b20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function atualizarFunc(event){ | |
// Codigo para reiniciar toda a table aqui | |
// Use o hide para "terminar" o pull to refresh | |
requisicaoXHR({ | |
refresh: event | |
}); | |
} | |
function carregarMais(event){ | |
requisicaoXHR({ | |
infinityScroll: event | |
}); | |
} | |
function requisicaoXHR(){ | |
var _args = arguments[0] || {}; | |
var xhr = Ti.Network.createHTTP({ | |
onerror:function(error){ | |
alert('Erro: ', error); | |
if(_args.refresh) _args.refresh.hide(); | |
if(_args.infinityScroll) _args.infinityScroll.success(); | |
}, | |
onload:function(success){ | |
var result = JSON.parse(this.responseText); | |
// | |
populaTableView({ | |
json: result | |
, refresh: _args.refresh // lembre que tem que passar o objeto de refresh para poder "parar" ele | |
, infinityScroll: _args.infinityScroll | |
}); | |
} | |
}); | |
} | |
function populaTableView(){ | |
var _args = arguments[0] || {}; | |
if(_args.refresh) $.tableView.data = []; // limpa a tableview | |
_args.json.forEach(function(node){ | |
// função para lidar com os dados e inserir na tableview | |
}); | |
if(_args.refresh) _args.refresh.hide(); | |
if(_args.infinityScroll){ | |
if(aindaPodePuxar_maisDados) _args.infinityScroll.success(); | |
else _args.infinityScroll.done(); | |
} | |
} | |
function openWindow(){ | |
// Tem que inicializar a infinity scroll desse jeito. | |
$.is.init($.tableView); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Window onOpen="openWindow"> | |
<!-- TableView --> | |
<Widget id="ptr" src="nl.fokkezb.pullToRefresh" onRelease="atualizarFunc"> | |
<TableView id="tableView" onClick="detalheRow"> | |
<Widget id="is" src="nl.fokkezb.infiniteScroll" onEnd="carregarMais" msgTap="Toque para carregar" msgDone="Não temos mais estabelecimentos ):" msgError="Ops algo deu errado, toque novamente"/> | |
</TableView> | |
</Widget> | |
</Window> | |
</Alloy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment