0
我有一個綁定用foreachKnockoutJS變動表型號到控制器
<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輸入模式videmodel一個dropdownbox當用戶改變下拉控制在同一屏幕上,我寫下了jscript。它已經改變了模型的新的價值,但它不是apearing上控制
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個控制其中的一個改變了我想看到的總是綁定到視圖模型的另一個控制。 self.gifts.XXX ='新值';我希望看到此上綁定控制
謝謝湯姆self.gifts()[self.gifts()長度-1。]。 muhasebekodu(值); – dewelloper