Bing地图和knockout.js

时间:2014-01-10 13:38:54

标签: knockout.js bing

我正在尝试在knockout.js foreach循环中显示Bing Map。但是我收到一条错误消息“TypeError:ft is null”。

但是,如果我不包括knockout.js那么它工作正常。

但我需要在我的项目中使用knockout.js的foreach循环。

任何帮助都将受到高度赞赏。

我的HTML文件: -

<div class="container contact-body-contents" data-bind="foreach: addresses">
    <p class="text-bold-head"  data-bind="text: location"></p>
    <span data-bind="html: address"></span>
    <span data-bind="text: phone"></span>
    <div id='myMap' style="position:relative; width:400px; height:400px;float: "right"> 
    </div>
</div>  

map.js

var map = null;         

function GetMap()
{
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById("myMap"),
             {credentials:"credentials"}); 

// Define the pushpin location
var loc = new Microsoft.Maps.Location(41.806358,-73.112144);

// Add a pin to the map
var pin = new Microsoft.Maps.Pushpin(loc); 
map.entities.push(pin);

// Center the map on the location
map.setView({center: loc, zoom: 15});
}

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,现在就解决了。

<div class="container contact-body-contents" data-bind="foreach: addresses">
    <p class="text-bold-head"  data-bind="text: location"></p>
    <span data-bind="html: address"></span>
    <span data-bind="text: phone"></span>
    <div id='myMap' style="position:relative;width:400px;height:400px;float: "right"> 
    </div>
</div>

<div id="myMap"放在data-bind元素之外。

<div class="container contact-body-contents" data-bind="foreach: addresses">
    <p class="text-bold-head"  data-bind="text: location"></p>
        <span data-bind="html: address"></span>
        <span data-bind="text: phone"></span>
</div>

<div id='myMap' style="position:relative;width:400px;height:400px;float: "right"> 
</div>