如何将数据存储值传递给 javascript?我需要从 gae 数据存储中获取数据并需要传递 javascript
How to pass the datastore value to javascript? i need to get data from the gae datastore and need to pass javascript
我正在使用 webapp2 与 GAE 合作,python。
现在正在使用 gae 在 google 地图中工作。已成功完成多个位置。
This is my JavaScript:
======================
<script type="text/javascript">
var USER_POSITION;
var DESTINATION_MARKER;
var ALL_MARKERS = [];
var coordinateArray = [
{coordinates: new google.maps.LatLng(12.9345494,77.6115174), id: "forum", title: "Forum", address_details: Bengaluru<br/>Karnataka-560095"},
{coordinates: new google.maps.LatLng(12.973584,77.611293), id: "central", title: "Central", address_details: Bengaluru<br/>Karnataka-560001"},
{coordinates: new google.maps.LatLng(12.956534,77.701239), id: "busstop", title: "Marathahalli", address_details: Bengaluru<br/>Karnataka-560037"}
];
</script>
这里使用的是硬编码值。但我需要传递我的数据存储值。
我如何将这些数据存储值传递给我的 javascript。
This is my DBModel:
====================
class MapModel(db.Model):
Lattitude=db.StringProperty()
Landitude=db.StringProperty()
Id=db.StringProperty()
Title=db.StringProperty()
Address=db.StringProperty()
请提供一些示例代码。
My.js:
var mapProperty = new google.maps.Map(document.getElementById("example"), myOptions;
for(var i in coordinateArray ) {
var id = coordinateArray[i]['id'];
var title = coordinateArray[i]['title'];
var position = coordinateArray[i]['coordinates'];
var address_details = coordinateArray[i]['address_details'];
var boxText = [
'<div class="info_box">',
..info details..
'</div>'
].join(" ");
var markerOptions = {
animation: markerAnimation,
position: coordinateArray[i]['coordinates'],
icon: markerImage,
map: mapProperty,
html: boxText,
id: id
};
您可以使用 webapp2 templates 将数据传递到您的 HTML 页面。
Python代码:
coordinates = MapModel.all()
template_values = {
'coordinates': coordinates
}
path = os.path.join(os.path.dirname(__file__), 'YourFile.html')
self.response.out.write(template.render(path, template_values))
在HTML页:
<script type="text/javascript">
var USER_POSITION;
var DESTINATION_MARKER;
var ALL_MARKERS = [];
var coordinateArray = [
{% for cord in coordinates %}
{coordinates: new google.maps.LatLng({{cord.Lattitude}},{{cord.Landitude}}), id: "{{cord.id}}", title: "{{cord.title}}", address_details: "{{cord.Address}}"},
{% endfor %}
];
</script>
我正在使用 webapp2 与 GAE 合作,python。 现在正在使用 gae 在 google 地图中工作。已成功完成多个位置。
This is my JavaScript:
======================
<script type="text/javascript">
var USER_POSITION;
var DESTINATION_MARKER;
var ALL_MARKERS = [];
var coordinateArray = [
{coordinates: new google.maps.LatLng(12.9345494,77.6115174), id: "forum", title: "Forum", address_details: Bengaluru<br/>Karnataka-560095"},
{coordinates: new google.maps.LatLng(12.973584,77.611293), id: "central", title: "Central", address_details: Bengaluru<br/>Karnataka-560001"},
{coordinates: new google.maps.LatLng(12.956534,77.701239), id: "busstop", title: "Marathahalli", address_details: Bengaluru<br/>Karnataka-560037"}
];
</script>
这里使用的是硬编码值。但我需要传递我的数据存储值。 我如何将这些数据存储值传递给我的 javascript。
This is my DBModel:
====================
class MapModel(db.Model):
Lattitude=db.StringProperty()
Landitude=db.StringProperty()
Id=db.StringProperty()
Title=db.StringProperty()
Address=db.StringProperty()
请提供一些示例代码。
My.js:
var mapProperty = new google.maps.Map(document.getElementById("example"), myOptions;
for(var i in coordinateArray ) {
var id = coordinateArray[i]['id'];
var title = coordinateArray[i]['title'];
var position = coordinateArray[i]['coordinates'];
var address_details = coordinateArray[i]['address_details'];
var boxText = [
'<div class="info_box">',
..info details..
'</div>'
].join(" ");
var markerOptions = {
animation: markerAnimation,
position: coordinateArray[i]['coordinates'],
icon: markerImage,
map: mapProperty,
html: boxText,
id: id
};
您可以使用 webapp2 templates 将数据传递到您的 HTML 页面。
Python代码:
coordinates = MapModel.all()
template_values = {
'coordinates': coordinates
}
path = os.path.join(os.path.dirname(__file__), 'YourFile.html')
self.response.out.write(template.render(path, template_values))
在HTML页:
<script type="text/javascript">
var USER_POSITION;
var DESTINATION_MARKER;
var ALL_MARKERS = [];
var coordinateArray = [
{% for cord in coordinates %}
{coordinates: new google.maps.LatLng({{cord.Lattitude}},{{cord.Landitude}}), id: "{{cord.id}}", title: "{{cord.title}}", address_details: "{{cord.Address}}"},
{% endfor %}
];
</script>