我是新的淘汰賽js.Trying對HTML實施倒計時用基因敲除的js淘汰賽JS如何實現倒數計時器
爲此我加4個HTML元素(輸入,跨度和啓動,停止按鈕)的觀點。當按下開始按鈕時,寫在<input>
對象上的值應該傳遞給refreshViewModel
,並且會有倒計時過程。倒計時處理剩餘時間將顯示在<span>
元素內。如果按下停止按鈕,則倒計時將停止。
如果倒數計時完成另一個函數(即從另一個viewModel回調),它將啓動一些參數過濾頁面。
約束值的綁定文本框值。我無法弄清楚如何計算和動態顯示範圍內的剩餘價值?
HTML:
<div id="pnlTimer" class="row">
<div class="span2 pull-right" style="border:1px solid rgb(218, 218, 218)" >
<span style="font-weight:bold">Reload Interval</span>
<br />
<input id="initialTime" style="width:20px;height:14px" data-bind="value: initialTime" />
<span id="remainingTime" style="visibility:hidden">/15</span> second(s)
<button class="btn" style="margin-top:5px" id="StartCounter" data-bind="click: StartCounter">
<i class="icon-play"></i>
</button>
<button style="visibility:hidden;margin-top:5px;margin-left:-44px" class="btn" id="StopCounter" data-bind="click: StopCounter">
<i class="icon-stop"></i>
</button>
</div>
</div>
JS:
@Url.Content("~/Content/App/viewModels/listCasesViewModel.js
@Url.Content("~/Content/App/viewModels/RefreshPageTimerViewModel.js
$(document).ready(function() {
var viewModel = new ListCasesViewModel();
viewModel.init();
var pnl = $("#pnlFilterPanel").get()[0];
ko.applyBindings(viewModel, pnl);
var viewModelTimer = new RefreshPageTimerViewModel();
viewModelTimer.init();
var pnlTimer = $("#pnlTimer").get()[0];
ko.applyBindings(viewModelTimer, pnlTimer);
viewModelTimer.callBackMethod = viewModel.filter;
});
第一視圖模型:RefreshPageTimerViewModel:
var RefreshPageTimerViewModel = function() {
var self = this;
self.StartCounter = ko.observable();
self.StopCounter = ko.observable();
self.initialTime = ko.observable();
self.remainingTime = ko.computed(function() {
return self.initialTime();
}, self);
countDown: ko.observable()
this.init = function() {
self.Count();
}
this.callBackMethod = function() {
alert("not implemented!");
}
this.Count = function() {
var initial = self.initialTime; // initialTime value;
var remaining = self.remainingTime;
if (remainingTime <= 0) {
this.ExecuteCallBackMethod();
}
}
this.ExecuteCallBackMethod = function() {
this.callBackMethod();
}
};
二視圖模型:ListCasesViewModel:
var ListCasesViewModel = function() {
var self = this;
self.selectedStartDate = ko.observable(null);
self.selectedEndDate = ko.observable(new Date());
self.selectedSearchKey = ko.observable("");
self.selectedStatuses = ko.observableArray();
self.selectedHospitals = ko.observableArray();
// methods...
this.init = function() {
self.selectedEndDate(new Date());
self.filter();
}
this.filter = function() {
// get filter control values
var startDate = self.selectedStartDate(); // dtStart.value();
var endDate = self.selectedEndDate(); //dtEnd.value();
var searchText = self.selectedSearchKey();
//And Some calculations....
謝謝,這是我尋找的例子。 小增加:「viewModelTimer.callBackMethod = viewModel.filter」引用從第二個viewModel到第一個的「filter()」函數。 – balron