I have a function that display a layer based on a SQL Query where the user insert a parameter in a form. I would like to reinitialize (empty) the layer at each new query without using a reset button. Thank you if you can help me.
There is the function:
function CS_query() {
CSsearch = document.getElementById('CS_Input').value;
layer_imm = new google.maps.FusionTablesLayer({
query: {
select: 'geometry',
from: '1ckqpE8ZxVzfgJ5bT-vAkpBwjVANbV-KiNjfScjw',
where: "CODE_CS LIKE '%" + CSsearch + "%'"
}
});
layer_imm.setMap(map);
}
Thank you for your answers guys.
google.maps.event.addDomListener(document.getElementById('CS'),
'click', CS_query);
layer_imm = new google.maps.FusionTablesLayer();
function CS_query() {
CSsearch = document.getElementById('CS_Input').value;
layer_imm.setOptions({
query: {
select: 'geometry',
from: '1_SY_lmkaQ3_3_pPDzho1-X9fc8WtdJGfo2w1VVg',
where: "CODE_CS LIKE '%" + CSsearch + "%'"
},
map:map
});
}
<input type="text" id="CS_Input">
<input type="button" id="CS" value="Submit" >
Related
Can anyone help me? My database has more field like this one:
[
{
"key":"word_1",
"Word":"a",
"Meaning":"a"
},
...
]
I already read it from database but how can I store it to state and render each element on Flatlist.
Here is way i get data from Database:
db.transaction(tx => {
var sql =
"SELECT * FROM tblVietAnh WHERE word LIKE '" +
this.state._inputValue.toLowerCase() +
"%' LIMIT 5";
tx.executeSql(sql, [], (tx, results) => {
var len = results.rows.length;
setState({ _records: results.row.item });
console.log(this.state._records);
for (let i = 0; i {
_records: prevState._records.push(row.id, row.word, row.meaning);
});
}
});
});
But by this way i just have an array with separate row. So I cant access to each element. How can I fix this ?
Thank you!
I am using knockout.js in my django project and having problem in post method in javascript. I tried to rebind or re-initialized the list but it didn't work.
Eg: I am showing table data with 10 rows..I want on button click I get another data with 5 rows and want to reload that data on table without reloading the page.
Does any one knows the solution .. Below is my code for knockout.js, html and view.py page:
javascript:
function makeShowObjectList(model, d_url, no_num, detail_per_page, b, fruit) {
var showobjectList = ko.observableArray([]);
$.post(d_url, data, function (response_data) {
// here we have applied code to set new data in showobjectList
if (!showobjectList.is_ready)
{
//Here we are trying to relaod the list on the page but did'nt work
FViewModel.showobjectList=showobjectList;
showobjectList.is_ready = true;
showobjectList.onready();
ko.mapping.fromJSshowobjectList, {}, self); }
}
}, 'json');
}
function fruitFilterItem( n, i ) {
this.n = n;
this.i = i;
}
var FViewModel=function(c_data)
{
var self = this;
self.abc= ko.observable(null);
this.optionsText = ko.observable();
this.fruitFilter = ko.observableArray([
new fruitFilterItem( "Mango", 2 ),
new fruitFilterItem( "Banana", 1 ),
new fruitFilterItem( "Grapes", 3 )
]);
this.selectedfruit = ko.observable();
this.VegeFilter = ko.observableArray([
new fruitFilterItem( "Tomato", "Tomato" ),
new fruitFilterItem( "Patato", "Patato" ),
new fruitFilterItem( "Onion", "Onion" ),
]);
this.selectedVege = ko.observable();
self.showtList = makeShowObjectList(BucketViewModel, urls.get_fruit_info, self.fruit_page, self.num_fruit, self.bbq,
self.selectedfruit());
self.setShowType = function(d, ele) {
this.get_updates = function () {
ko.mapping.fromJS(searchList(), self);};
self.showtList = makeShowObjectList(BucketViewModel, urls.get_fruit_info, self.fruit_page, self.num_fruit, self.b, self.selectedfruit());
self.showtList();
}
self.ShowmessageList = function () {
return self.showtList;
}
}
HTML:
<script>
VarModel = new FViewModel(c_data);
$(function() {
function get_updates () {
$.getJSON('/new-lines.json', function(c_data) {
var VarModel = ko.mapping.fromJS(choices_data);
ko.applyBindings(VarModel );
});
}
ko.applyBindings(VarModel);
</script>
<body>
<select id="fruit" name="fruit" style="width:200px;" data-bind = "
value: selectedfruit,
options: fruitFilter,
optionsText: 'n',
optionsValue: 'i',
optionsCaption: 'Select a fruit'
">
</select>
<select style="width:180px;" data-bind = "
value: selectedVege,
options: VegeFilter,
optionsText: 'n',
optionsValue: 'i',
optionsCaption: 'Select a Vege'
">
//here we are showing our columns
</body>
Views.py:
def urls.get_fruit_info(request):
//we are calculating the page_object here
response_object = {
'page': page_object,
'no_not': FruitRecipient.objects.filter(user=request.member, add_at=None).count()
}
return HttpResponse(simplejson.dumps(response_object, indent=3))
I would be thankful if any one could help me out in sorting my issue.
Thanks in advance.
Use ko.mapping its a plugin that you can download, it only updates the observables that have changed between two states, thus only the members that have changed will be re re-rendered in the view
I'm on symfony 2.2 + FoqElasticaBundle
I try to use autocomplete from a result query elasticsearch
<input type="text" class="span3" id="search" data-provide="typeahead" data-items="4" />
var subjects = ['PHP', 'MySQL', 'SQL', 'PostgreSQL', 'HTML', 'CSS', 'HTML5', 'CSS3', 'JSON'];
$('#search').typeahead({source: subjects})
autocomplete works like this, but...
How to get my elasticsearc url replace the subjects like this?
var subjects = "http://myhost:9200/_search?pretty=true";
I want that the source of my autocomplete is the result of my query elasticsearch
With typeahead you can use the data coming from the server like:
function search() {
$('#search').typeahead({
source: function (query, process) {
return $.get("{{path("url_to_fetch_from_server", {_format: "json"})}}", { "query" : query }, function (data) {
return process(data);
});
}
});
};
$(function(){
search();
});
As you can see the typeahead source function take 2 arguments.
query is the text type in the typeahead box. you need to pass this to the server
process is the callback.
The server should response back in JSON format. you can replace "{{path("url_to_fetch_from_server", {_format: "json"})}}" to your real url.
public function queryAction(){
$query = $this->getRequest()->query->get("query");
$gType = $this->container->get('foq_elastica.finder.search_db');
$results = $gType->find($query, 20);
$tools = [];
foreach($results as $result){
$tools[] = $result->getTool();
}
return new Response(json_encode($tools));
}
I am trying to develop an android mobile application using the PhoneGap framework, and I want to synchronize my table of local database(of my phone) to the server database.
this is my code, but this code allow me to send only one line of table how can i send all line of table.
$.ajax({
type: 'POST',
data: col1+'&lid='+col2,
url: 'http://your-domain.com/comments/save.php',
success: function(data){
console.log(data);
alert('Your data was successfully added');
},
error: function(){
console.log(data);
alert('There was an error adding your data');
}
});
Try to select the data from the localDatabase and send it row by row, here's an example:
db.transaction(function(tx) {
Squery = 'SELECT * FROM news WHERE category_id ='+lid;
tx.executeSql(Squery,
null,
function(tx, results)
{
for(i=0; i<results.rows. length; i++){
row = results.rows.item(0);
$.ajax({ -- your code using row['name_of_column'] -- })
}
},
console.log('error')
});});
sorry for my miss understoods...
If you are using phonegap i guess you are using the Storage feature: http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#Storage
folowing one of theirs examples, you can do something like:
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
//do you ajax request....
...
data: {
rows : results.rows
}
...
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
other option is to send a simple array...
function querySuccess(tx, results) {
var myRowsIds = [];
var len = results.rows.length;
for (var i=0; i<len; i++){
myRowsIds .push( results.rows.item(i).id )
}
//do you ajax request....
...
data: {
rows : myRowsIds
}
...
}
hope it helps!
This may sound rather simple but how do you pass the variables of the SELECT function to populate a div form?
I've successfully set up FC and use the SELECT function to trigger the appearance of a form "new_event".
select: function( startDate, endDate, allDay, jsEvent, view) {
$("#new_event").show();
},
I now need to populate the form with the startDate etc. Once completed the form will then make the necessary changes to a mySQl backend via PHP.
Here is my select which generates the add event form
select: function(start, end, allDay) {
var calendars = getAjaxData('calendar/calendarsJson');
var txt = '<h3>Dodaj nov dogodek:</h3>\n\
<div class="clear"></div>\n\
<p><label>'+CI.lang.language.what+':</label><input type="text" name="title" value="" /></p>\n\
<p><label>'+CI.lang.language.where+':</label><input type="text" name="location" value="" /></p>\n\
<p><label>'+CI.lang.language.description+':</label></p>\n\
<p><textarea name="description"></textarea></p>';
txt += '<p><label>'+CI.lang.language.calendar+':</label>\n\
<select name="id_calendar">';
for(i=0;i<calendars.length;i++) {
txt += '<option value="'+calendars[i].id_calendar+'">'+calendars[i].title+'</option>';
}
txt += '</select></p>';
txt += '<br />';
//txt += '<input type="button" value="'+CI.lang.language.create_event+'" />'
var btns = {};
btns[CI.lang.language.create_event] = true
btns[CI.lang.language.cancel] = false;
$.prompt(txt,{
prefix:'event_box',
callback: dodaj,
buttons: btns
});
function dodaj(v,m,f){
if(f && v){
var classN = getAjaxData('calendar/getClassJson/'+f.id_calendar);
var nEvent = {
title: f.title,
description: f.description,
location: f.location,
start: start,
end: end,
allDay: allDay,
className: classN,
id_calendar: f.id_calendar
};
if (f.title) {
calendar.fullCalendar('renderEvent',
nEvent,
false // make the event "stick"
);
}
addEvent(nEvent);
calendar.fullCalendar('refetchEvents');
}
calendar.fullCalendar('unselect');
}
},
Here is the addEvent function which submits new data to db using JSON:
function addEvent(event) {
var start = my_convertDate(new Date(event.start));
var end;
if(event.end === null) {
end = start;
} else {
end = my_convertDate(new Date(event.end));
}
if((event.allDay)){
event.allDay = 1
} else {
event.allDay = 0;
}
var eventData = {
start_date : start.date,
start_time : start.time,
end_date : end.date,
end_time : end.time,
id_event : event.id,
all_day : event.allDay,
title: event.title,
className: event.className,
location: event.location,
description: event.description,
id_calendar: event.id_calendar
}
makeAjaxRequest('event/addEventJson', eventData);
}