Sort the bus schedule?
In the tutorial project "Building a Clickable List App with HTML5 Local Storage" if I wanted to sort the RoutesService response by @tag, what might be a good way to to do it?
B2
Catch up wih the Appery.io community on our forum. Here you'll find information on the lastest questions and issues Appery.io developers are discussing.
https://forum.appery.io/
In the tutorial project "Building a Clickable List App with HTML5 Local Storage" if I wanted to sort the RoutesService response by @tag, what might be a good way to to do it?
B2
Hello Brian!
You can sort it with JavaScript.
Look here https://getsatisfaction.com/apperyio/...
I think I'm awfully close, but I'm still missing something.
I added the JS plug-in (jQuery.fn.sortElements) and mapped the service response fields to the labels. Does the following look about right for the JS to run on success? (mobilelistitem name = mobilelistitem1_3, the hidden field name = tagID)
function compareFunc(a, b) {
var first, second;
first = $("[name=tagID]", a).text();
second = $("[name=tagID]", b).text();
return +first - (+second);
}
var $li = $("[name=mobilelistitem1_3]:gt(0)"); //:gt(0) - we don't need first element. it's used for mapping
$li.sortElements(compareFunc, function(){ return this;});
Hello Brian.
Do you get any errors in the console?
Please provide us a publick link to your app or share it with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a.
Hi,
No errors are thrown but the sorting is not happening. I shared the project "Bus sched tutorial" with you.
-thanks!
Hi Brian.
The problem is in tagID field. It has numbers and strings (for example '1BX', 'K OWL'). Try to use
return first second ? 1 : -1;
instead of
return +first - (+second);
That works. Thank you so much! (Now... to figure out exactly how it works. I'm still learning JS...)