【发布时间】:2016-03-18 02:32:26
【问题描述】:
我正在尝试将数据从服务器发送到网站,并使用该数据在聚合物地图上自定义标记。我正在使用 socket.io,当我尝试更改标记属性时,我的标记不显示。
这是一个代码:
<dom-module id="main-map">
<template>
<style>
google-map {
display: block;
width: 100%;
height:100%;
}
</style>
<google-map map="{{map}}"
latitude="52.0535631"
longitude="19.5249493"
zoom="7"
disable-default-ui >
<template is="dom-repeat" items="{{xMarker}}">
<google-map-marker map={{map}}
latitude="{{item.latitudine}}"
longitude="{{item.longitudine}}"
animation="{{item.animation}}">
</google-map-marker>
</template>
</google-map>
</template>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
Polymer({
is: 'main-map',
properties: {
xMarker: {
type: Object,
value: function () {
socket.on("asd", function (data) {
var obj = {};
obj = [{
latitudine: '52.0535631',
longitudine: '19.5249493',
animation:'BOUNCE',
}];
console.log(obj);
return obj;
})
}
}
}
});
</script>
</dom-module>
【问题讨论】:
-
也许我在 PolymerJS 编写代码的方式上遗漏了一些东西,但您不需要实例化您的套接字吗? var socket = io()?
-
sockets 工作正常,我之前定义了 socket。我猜这可能是数据绑定的问题
标签: javascript google-maps data-binding polymer