我有一个与foreach
绑定到videmodel的下拉框<td>
<input class='required' type="text" data-bind="value: muhasebekodu" id="muhasebekodu" /></td>
<td>
<select data-bind="options: gidertipleri, value: selectedOptionValue" onchange="SetCodeField(this.value);" id="muhcodes" name="muhcodess"></select></td>
这样的模型
var self = null;
var viewModel = null;
$(document).ready(function () {
var giderlers = JSON.parse(document.getElementById('ContentPlaceHolder1_hdnOutgoingTypes').value);
var selectedGider = document.getElementById('ContentPlaceHolder1_hdnOutgoingTypesSelected').value;
var odemetipleri = JSON.parse(document.getElementById('ContentPlaceHolder1_hdnFirmPaymentTypes').value);
var selectedOdemeTipi = document.getElementById('ContentPlaceHolder1_hdnFirmPaymentTypesSelected').value;
var GiftModel = function (gifts) {
self = this;
self.gifts = ko.observableArray(gifts);
self.addGift = function () {
self.gifts.push({
muhasebekodu: ko.observable().extend({ notify: 'always' }),
gidertipleri: giderlers,
selectedOptionValue: ko.observable(selectedGider),
faturano: "",
matrah: "",
kdv: "",
geneltoplam: "",
kdvtipleri: ["0", "1", "8", "18"],
selectedOKDVptionValue: ko.observable("0"),
odemeseklitipleri: odemetipleri,
selectedOOSTptionValue: ko.observable(selectedOdemeTipi),
aciklama: "",
});
};
self.removeGift = function (gift) {
self.gifts.remove(gift);
};
self.save = function (form) {
alert("Could now transmit to server: " + ko.utils.stringifyJson(self.gifts));
// To actually transmit to server as a regular form post, write this: ko.utils.postJson($("form")[0], self.gifts);
};
};
viewModel = new GiftModel([
{ muhasebekodu: ko.observable().extend({ notify: 'always' }), gidertipleri: giderlers, selectedOptionValue: ko.observable(selectedGider), faturano: "", matrah: "", kdv: "", geneltoplam: "", kdvtipleri: ["0", "1", "8", "18"], selectedOKDVptionValue: ko.observable("0"), odemeseklitipleri: odemetipleri, selectedOOSTptionValue: ko.observable(selectedOdemeTipi), aciklama: "" },
]);
ko.applyBindings(viewModel);
// Activate jQuery Validation
//$("form").validate({ submitHandler: viewModel.save });
$(".faturanoinp").bind('keyup', function (e) {
$(this).val($(this).val().toUpperCase());
});
});
我想在用户在同一屏幕上更改下拉控件时设置我的muhasebekodu输入,我在jscript下面写了。它已经改变了模型中的新值,但它并没有改变控制
function SetCodeField(e) {
var mcode = document.getElementById('ContentPlaceHolder1_hdnmuhasebekodlari').value;
var mcodes = mcode.split(",");
for (i = 0; i < mcodes.length; i++) {
var namevalues = mcodes[i].split(":");
var name = namevalues[0];
var value = namevalues[1];
if (e == name) {
self.gifts()[self.gifts.length].muhasebekodu.value = value;
self.gifts()[self.gifts.length].muhasebekodu.extend({ notify: 'always' });
}
}
}
我有2个控件其中一个已更改我想在另一个控件上看到始终绑定到viewmodel。 self.gifts.XXX ='新值';我想在绑定控件上看到这个
答案 0 :(得分:1)
在淘汰赛中你可以像这样设置一个observable的值:
self.gifts()[self.gifts.length].muhasebekodu(value);