2014-01-10 90 views
0

我試圖在knockout.js foreach循環中顯示Bing地圖。但是我收到一條錯誤消息「TypeError:ft is null」。Bing地圖和knockout.js

但是,如果我不包括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}); 
} 
+0

請張貼您的代碼的一些幫助。你想做什麼的想法是好的。 –

+0

問題不在於你顯示的代碼部分。嘗試創建一個最小化的測試用例來重現問題併發布。 – ebohlman

回答

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"

<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>