I try to make a simple application with Intel XDK and Parse.com as backend service.
I made a listview like this tutorial shows.
The listview, in my app, displays the newest entries at the bottom. Instead of that i want to show the list with the opposite way - the most recent entries at the top of the list.
In a simple HTML5-JS file i do it with query.ascending("createdAt");
as described in documentation for JavaScript in Parse.com. How i can do it so with Intel XDK?
I will appreciate every helpfull answer.
EDIT after the first answer from Chris Perkins
I managed to integrate my Parse.com database in Intel XDK as external web service according to this answer.
So, in -----/www/xdk/services/service-methods.js, the part of method invoked by my service looks like this:
intel.xdk.services.iodocs_.New_Service = ((function (credentials) {
var exports = {};
exports.ServiceObject = function(params) {
var url = 'https://api.parse.com/1/classes/ServiceObject';
return $.ajax({
url : url,
headers : {
'X-Parse-Application-Id' : credentials.apiKey,
'X-Parse-REST-API-Key' : credentials.apiSecret
}
});
};
return exports;
}))(intel.xdk.services.credentials.New_Service,intel.xdk.services.iodocs_.helpers);
If I have understood correctly the array that i want to display reversely is the value of the "results" in the Respond Body of my service and all this is within the curly brackets of var exports = {};
. I am right or not?
that's a feature we haven't yet provided. We very much want users to be able to filter, transform, and reorder service request data. If you have any suggestions or ideas, let us know. Our idea right now is that we will have a convention. If the service is named intel.xdk.foo, then anything named intel.xdk.foo.filter will be automatically invoked such that it receives the resulting data as an argument and can return modified data.
But that's not in yet. In the interim, do this:
1 - In the XDK click the Settings gear at the far right of the toolbar. Go to the services tab and turn OFF minification.
2 - Open yourproject/www/xdk/services/service-methods.js Find the method invoked by your service method in there. It probably looks something like this:
return $.ajax({
url: url,
type: 'GET'
});
3 - Use promise chaining to change that result. In your case, let's say the data is an array and we want to reverse it (probably both bad assumptions):
return $.ajax({
url: url,
type: 'GET'
}).then(function(data){
return Array.prototype.reverse(data);
});
Does that make sense?
I tried what suggested above, but the list was not even created.
The solution was not the way the database associated with the application.
I realized that the list is created in a template and that the solution lies in the backbone.js file. So, i opened the -----/www/js/backbone_support.js and tried to intervene by doing something similar to this
var myCollection = Backbone.Collection.extend({
model: myModel,
comparator: function(item) {
return -item.get('');
}
});
or to find somewhere a line with something like this
$('#list').append(listItem.render().el);
and change the .append()
to .prepend()
.
Nothing helped me. But eventually I noticed those lines in the code
//non-destructive reverse
var nd_reverse = function(arr){ return _.initial(arr, 0).reverse(); };
I deleted the .reverse()
and it happened. Now the list displays the newest entries of my Parse.com database at the top.
I don't know if this is the propper solution or if it is suitable for more complex issues but i hope to help somehow.