jqueryを使用してドロップダウンを作成するためのKnockOutに関するコードも取得しました。私は KnockOut にまったく慣れていないので、それがどのように機能するかを理解できるようになりました。
ノックアウト関連のコードの意味を教えてください。ここに完全なコードがあります
<p>
Your country:
<asp:DropDownList ID="ddlCountries" runat="server" data-bind="options: countryModel.countries, optionsValue: 'CountryID', optionsText: 'CountryName', optionsCaption: 'Choose...'">
</asp:DropDownList>
</p>
<input type="button" value="Add" data-bind="click: addCountry" />
<script type="text/javascript">
function DropDownModel() {
var self = this;
self.countries = ko.observableArray();
self.addCountry = function () {
$.ajax({
type: "POST",
url: "DropDownSolution.aspx/GetCountries",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
self.countries(data.d);
}
});
};
}
var countryModel = new DropDownModel()
ko.applyBindings(countryModel);
</script>
WebMethod]
public static List<Country> GetCountries()
{
List<Country> countries = new List<Country>();
countries.Add(new Country { CountryID = "1", CountryName = "India" });
countries.Add(new Country { CountryID = "2", CountryName = "Singapore" });
countries.Add(new Country { CountryID = "3", CountryName = "Malaysia" });
return countries;
}
私の懸念は、KnockOut 関連のコードを理解できないことです。
ko.applyBindings(countryModel);
コって何?
var self = this;
self.countries = ko.observableArray();
self = this means what....so self hold which reference?
self.countries = ko.observableArray();
what is ko and how ko comes?
what is observableArray() & what is does?
self.addCountry = function () { addCountry DropDownModel() 関数が呼び出されると自動的に発火するようです。どのように関数を自動的に呼び出すことができますか?
KnockOut がドロップダウンに入力する方法....ドロップダウンに入力する方法を理解する方法。
詳しく教えてください。ありがとう