,我的html页面上有一个滑块,它有一个可观察的数据绑定。 像这样。
<input id="ex2" data-slider-id="ex2Slider" type="text" data-bind="sliderValue: {value: borrowOrInvestAmount, min:0, max: 5000, step: 1, formatter:formatter2}"
style="display: none;">
而且我还有一张表显示出这样的兴趣。
<td <input data-bind=" valueUpdate: 'afterkeydown'"><input data-bind="value: amount1"/></td>
基本上我想要的是,当我更改滑块上的值时,它应该调用此函数,该函数从可观察的borrowOrInvestAmount中获取值 并且应该返回将被放入观察中并显示在桌面上的利率。每次滑块值改变时,它应该再次调用该函数。
function DoBusinessViewModel(root) {
var self = this;
self.items = ko.observableArray();
self.itemsNotFoundMsg = ko.observable(null);
var borrowOrInvestAmount_tmp = 0;
var moneyBorrOrInvUri;
if (root.boolInvestments()) {
moneyBorrOrInvUri = BASEURL + 'index.php/moneyexchange/SearchRequestsOrInvestments/' + auth + '/' + root.borrowOrInvestAmount() + '/' + root.borrowOrInvestCurrency() + '/' + 0 + '/' + 1;
} else {
moneyBorrOrInvUri = BASEURL + 'index.php/moneyexchange/SearchRequestsOrInvestments/' + auth + '/' + root.borrowOrInvestAmount() + '/' + root.borrowOrInvestCurrency() + '/' + 0 + '/' + 0;
}
$.ajax({
type: 'GET',
url: moneyBorrOrInvUri,
contentType: 'application/json; charset=utf-8'
})
.done(function(BorrowOrInvestDetails) {
$.each(BorrowOrInvestDetails, function (index, item) {
self.items.push(item);
/* here is where I am trying to get the value of interest from for the table*/
self.interest(self.item()[0].Interest);
borrowOrInvestAmount_tmp += parseFloat(item.borrowOrInvestAmount);
/* If we are reading borrowing request and thee are any requests with payment_term = 2 = Monthly,
* we must set root.paymentTerm observable to 2 = Monthly. */
if (!root.boolInvestments()) {
if (item.payment_term == 2) {
if (root.paymentTerm() == 1) {
root.paymentTerm(2);
}
}
}
});
root.borrowOrInvestAmount(borrowOrInvestAmount_tmp.toFixed(2));
root.borrowOrInvestAbbreviation(self.items()[0].Abbreviation);
if (root.boolInvestments()) {
root.getFee(root.borrowOrInvestAmount(), root.borrowOrInvestCurrency(), 'money_request', 'borrow');
} else {
root.getFee(root.borrowOrInvestAmount(), root.borrowOrInvestCurrency(), 'money_offer', 'invest');
}
root.getPaymentPlanForMultibleItems(self.items());
})
.fail(function(jqXHR, textStatus, errorThrown) {
self.itemsNotFoundMsg(errorThrown);
})
.always(function(data){
});
};
由于我将值borrowOrInvestAmount添加到滑块我不确定它是否实际调用了dobusinessfunction。不知道我错过了什么。