2016-02-28 54 views
2

当我点击​​不在表格中时表现很好。表格里面的div标签

enter image description here

但是,当我在<input type="text" class="form-control" value="13:25">表点击这是行不通的。为什么?

enter image description here

@{ 
ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 
<link href="~/assets/css/bootstrap.css" rel="stylesheet" /> 
<link rel="stylesheet" type="text/css" href="dist/bootstrap-clockpicker.min.css"> 
<link rel="stylesheet" type="text/css" href="assets/css/github.min.css"> 

<script type="text/javascript" src="assets/js/jquery.min.js"></script> 
<script type="text/javascript" src="dist/bootstrap-clockpicker.min.js"></script> @*it's not a function*@ 
<script type="text/javascript" src="assets/js/highlight.min.js"></script> 
<script src="~/Scripts/knockout-2.2.0.js"></script> 

<div class="input-group clockpicker" data-align="top" data-autoclose="true"> 
    <input type="text" class="form-control" value="13:14"> 
</div> 

<table> 
<thead> 
    <tr><th>Name</th><th>time</th><th>Time input</th></tr> 
</thead> 
<tbody data-bind="foreach: items"> 
    <tr> 
     <td data-bind="text: name"></td> 
     <td data-bind="text: time"></td> 
     <td> 
      <div class="input-group clockpicker" data-align="top" data-autoclose="true"> 
       <input type="text" class="form-control" value="13:25"> 
      </div> 
     </td> 
    </tr> 
</tbody> 
</table> 

<script type="text/javascript"> 
$('.clockpicker').clockpicker(); 

function MyViewModel() { 
    var self = this; 
    self.items = ko.observableArray([{ name: 'jhon', time: '11:00' }, { name: 'David', time: '12:00' }]); 
} 
ko.applyBindings(new MyViewModel()); 
</script> 

更新:

卡伦德扩大

<ul> 
<li> 
    <div class="input-group clockpicker" data-align="top" data-autoclose="true"> 
     <input type="text" class="form-control" value="13:14"> 
    </div> 
</li> 

卡伦德不扩大

<ul data-bind="foreach: items"> 
<li> 
    <div class="input-group clockpicker" data-align="top" data-autoclose="true"> 
     <input type="text" class="form-control" value="13:14"> 
    </div> 
</li> 

问题在挖空?

+0

数据绑定可能已经保留?和控制台显示任何错误? – daremachine

+0

我在控制台中看不到任何错误。数据绑定仅使用一次。 – A191919

+0

和你试图把功能的股利,如果它的工作明确表? – daremachine

回答

1

因为Knockout JS在调用时钟init之外的其他时间绑定(创建)表,所以在表中不工作。您可以使用设置延迟initalization像:

setTimeout(function() { 
    $('.clockpicker').clockpicker(); 
}, 300); 

,这是正常的做法,但淘汰赛JS提供了自己的解决方案。 其中一种有用的解决方案可以是observable