There’s the library jLinno, I’ve used this library and it served me very well, I didn’t use the part of GROUP BY
(but if you look at the source there is the group()) method, I’ve always used but the filter and Sort part of the library.
But checking here the part of group by
also works correctly, although not in the demos of the developer site, I made some examples to illustrate its functioning:
// filtro nomes de paises que iniciam "B" na lista
var result = jlinq.from(array)
.starts("country.nome", "B")
.select();
And an example of GROUP BY
:
// Agrupa array por nome do pais
var resultGroup = jlinq.from(array)
.group("country.nome");
Follows this online example that best illustrates its functioning.
Edit
According to @Thiago’s comment, the question arose of how to specify the fields (or format) of the return in a query with the library jLinno. So I created an example for this situation as well:
// você consegue fazer um select no que você quer retornar
var result = jlinq.from(array)
.starts("country.nome", "B")
// o 'rec' é um alias da consulta
.select(function(rec) {
// returnando um objeto no formato que você desejar
return {
id:rec.id,
};
});
Or even as per @Thiago’s doubt, in the case of it you can even simplify and return only an array of ids:
var result = jlinq.from(array)
.starts("country.nome", "B")
.select(function(rec) {
return rec.id
});
Follows the online example of that new implementation.
Don’t you get an object or something? Post it...
– Ronny Amarante
yes and there’s the code of how I build my object
– Lugarini
You want to be able to make a GROUP BY (for example) in a javascript array easily?
– Fernando Leal
Are you using any graphics library? Does this database that is coming by jQuery come from a database? If yes, you could group by in the database before generating the Javascript object.
– Guilherme de Jesus Santos
yes, the
GROUP BY
also.. as I said, I will generate several graphs on the page, so I need something easy to handle my base by javascript– Lugarini
@Guilhermejsantos I can’t do the commands in the database =/ I don’t have access
– Lugarini
Has the jLinno, I’ve used this library and it served me very well, I didn’t use the part of
GROUP BY
(but if you look at the source there’s a methodgroup()
), I always used but the part of filters and Sort.– Fernando Leal
@Fernando thanks, I’ll try!
– Lugarini
@Fernando you q already used this library can help me so... I looked at an example on the page and this well:
jlinq.from(data.users).select()
in my case, just put my object(wo
) in place ofdata.users
?– Lugarini
@Thiago, edit the question and post an example of your array with some 10 items and what kind of operation you would like to do with it, which I see here how to do (if possible) and put as answer if it works. But to answer your question, yes, the
data.users
of the example is the list/array where the commands/filters/operations will be applied, in your case it seems to be thewo
.– Fernando Leal
@Fernando in the post has exactly the code that I use to build my array of objects... but by the way I’m doing something wrong... the script is returning to the following msg: jLinq can only query arrays of Objects. I believe q is some adjustment in the array construction..
– Lugarini
@Fernando now edited and put the complete code... once we arrive at a solution, just you answer the post q Mark as answer
– Lugarini
@Thiago, this error occurs when you try to pass to jLine an object that is not an array. If you search your source for the error message you will see this check.
– Fernando Leal
@Fernando but looking at my code, it seems to be all right in the construction of the object array...
– Lugarini
Let’s go continue this discussão in chat.
– Lugarini