2013-03-09 49 views
0

第一个问题!希望我做得很好。淘汰赛jQuery的结合点击不起作用

我有这样的绑定列表:

<table id="restaurants_list" data-bind="foreach : restaurants" style="display: none"> 
    <tr> 
     <td data-bind="text:name"></td> 
     <td data-bind="text:address.address1"></td> 
     <td data-bind="text:address.address2"></td> 
     <td data-bind="text:address.postcode + ' ' + address.suburb"></td> 
     <td> 
      <input type="button" value="show" data-bind="click: $root.showmap" /> 
     </td> 
    </tr> 
</table> 
<div id="map"></div> 

这里的模型视图:

function RestaurantsViewModel() { 
    var self = this; 
    self.restaurants = data; 
    self.showMap = function (restaurant) { 
     $("#map").show(); 
     .... 
    }; 
    showMap(restaurants[0]); 
}; 

最后绑定:

$(document).ready(function() { 
    $("#link_get_restaurants").bind("click", get_restaurants); 
}); 
function get_restaurants(event) { 
    $("#restaurants_list").show(); 
    ko.applyBindings(new RestaurantsViewModel()); 
} 

第一showmap(restaurants[0])工作正常。但是,click : $root.showmap不会触发。

所以做我做错了什么?我也使用Jquery,我不知道它是否可以来自此。

谢谢。

+0

有一个键入y我们目前的示例:在您的视图模型中,您有** showmap **,大写为'M',但在您的绑定中,您可以'用'小写'm'单击$ root.showmap'。将它改为'click:$ root.showMap' – nemesv 2013-03-09 07:59:43

回答

5

尝试这些2个步骤:

1)更换

click : $root.showmap

click : $root.showMap 

2)诅咒的情况下灵敏度:)

+0

对我感到羞耻!!!!!非常感谢,花了1个小时来寻找Jquery和Knockout之间复杂的混合! – Yoann 2013-03-09 08:37:40

+0

第2步非常重要! – 2013-08-16 09:26:08

2

showmap拼写错误的结合(你的方法是showMap)。你可以尝试绑定到$root.showMap

<input type="button" value="show" data-bind="click: $root.showMap" />