通過大量的實驗,我可以綁定我的第一個下拉列表。所以我的下一步是選擇一個下拉列表的值。我遵循下面的方式。訪問從下拉列表中選擇的項目值敲出js
<div id="divcountry">
<span>Country </span>
<select data-bind="options: CountriesList,optionsText: 'CountryName',optionsValue:'CountryId',value:CountryId,optionsCaption: 'Select Country..'" style="width: 148px">
</select>
</div>
var countryModel = {
CountriesList: ko.observableArray([])
};
var countryViewModel = function() {
var self = this;
self.CountryModel = countryModel;
// self.validateCountry = ko.validation.group(self.CountryModel, { deep: true });
self.CountriesList = ko.observableArray([]);
self.CountryId = ko.observable();
}
var stateModel = {
StateId: ko.observable(0),
StateName: ko.observable('').extend({ required: true }),
ShortName: ko.observable('').extend({ required: true }),
IsActive: ko.observable(true),
CountryId: ko.observable()
};
var stateViewModel = function() {
var self = this;
self.StateModel = stateModel;
// self.validateState = ko.validation.group(self.CountryModel, { deep: true });
self.StatesList = ko.observableArray([]);
//Handle Submit
self.Submit = function() {
// if (self.validateCountry().length == 0) {
if (self.StateModel.StateId() > 0) {
self.UpdateCountry();
} else {
self.AddState();
}
// self.Reset();
}
// }
現在我的疑問是什麼,但我們可以訪問countryViewModel
數據這是我StateModel self.CountryId
? 請給我發送CountryId
到服務器端的代碼!
stateModel不是構造函數??? –
@Aj_sari好的,很好,但是這並沒有改變答案,只是對代碼中最不重要的部分進行了微小的調整。我將編輯代碼。 – xdumaine