2017-06-18 9 views
2

私はノックアウトにはかなり新しいので、小さなアプリケーションを動作させる方法を理解しようとしています。基本的には、Googleマップをクリックして私のリストから場所を拡大したい。 Googleマップの一部が機能しています。私はノックアウトforeachメソッドを使用して記入するリストを作成しました。それでは、アイテムの値を関数にバインドしましたが、エラーがスローされ続けます。ノックアウトを介してクリックされた入力値を取得する

"knockout-3.4.2.js:1871 Uncaught ReferenceError:バインディングを処理できません" {return places} " メッセージ:結合処理できません "をクリック:

をここでは、この部分のための私のhtmlである:ここでは

<div class="scroll" id="myUL"> 
    <ul data-bind="foreach: places"> 
    <li> 
     <input data-bind="value: title, click: zoomToPlace" type="button" class="btn btn-small btn-link"> 
    </li> 
    </ul> 
</div> 

は私のjsです:関数()" zoomToPlaceが定義されていない メッセージ" {zoomToPlaceを返します} :

function PlacesList() { 
var self = this; 
self.places = ko.observableArray(locations); 
self.title = ko.observable(); 
self.zoomToPlace = function() { 
    // Initialize the geocoder. 
    var geocoder = new google.maps.Geocoder(); 
    // Get the place. 
    var address = this.title(); 
    // Geocode the address/area entered to get the center. Then, center the map on it and zoom in 
    geocoder.geocode({ 
     address: address, 
     componentRestrictions: { 
      locality: 'North York' 
     } 
    }, function(results, status) { 
     map.setCenter(results[0].geometry.location); 
     map.setZoom(15); 
    }); 
} 
} 

ko.applyBindings(new PlacesList(), document.getElementById("myUL")); 

ありがとうございました。ご了承ください。

答えて

0

変更zoomToPlace~$parent.zoomToPlace

forEachループ内では、コンテキストは現在のplacesです。 zoomToPlaceplacesのアイテムのメソッドではないので、エラーが発生しています。

+1

私はあなたにどれだけの感謝を表しているのですか?それは働いた! –

+0

驚くばかり!あなたはそれが働いてうれしい – DonovanM

関連する問題