I want to create a dynamic query (Select * from <table name> where ..) using angular js, html, javascript. The drop-down should come for the conditions ('and' , 'or', etc) e.g. -> select <dropdown> from <dropdown> where <dropdown> .
I am new to it. So please explain in proper example.
-
2Please share what have you tried so far.Pirate X– Pirate X2016-06-22 06:11:08 +00:00Commented Jun 22, 2016 at 6:11
-
A simple example would be make an ajax call to your controller to get data from the database and then bind the data to your drop down.SiddP– SiddP2016-06-22 06:13:44 +00:00Commented Jun 22, 2016 at 6:13
-
Can u please show an example?Priyanka– Priyanka2016-06-22 06:14:31 +00:00Commented Jun 22, 2016 at 6:14
-
Here see an example from question already asked in SO - stackoverflow.com/questions/15688313/…SiddP– SiddP2016-06-22 06:15:24 +00:00Commented Jun 22, 2016 at 6:15
-
I think you should at least try to start to implement something before you ask for help on SO, and if you have, please share it with us.Prince John– Prince John2016-06-22 06:28:32 +00:00Commented Jun 22, 2016 at 6:28
Add a comment
|
1 Answer
$.ajax({
type: 'POST',
url: 'DropDownController',
dataType: 'json',
success: function(result) {
$.each(result, function() {
$("#drpDown").append(
$('<option/>', {
value: this,
html: this
})
);
});
}
});
What happens at the endpoint is some controllerDropDownController may be if you are using Spring MVC it would be something like /DropDownController where you can write you query to call database using orm or whatever you use and returned is json which binds to the dropdown with id="drpDown"