Jquery 敲除用于填充组合时的工作原理
我也得到了一段关于使用jquery填充下拉列表的敲除的代码。 我一点也不熟悉击倒,所以我现在能够理解它是如何工作的 所以请告诉我敲除相关代码的含义。 这是完整的代码Jquery 敲除用于填充组合时的工作原理,jquery,knockout.js,Jquery,Knockout.js,我也得到了一段关于使用jquery填充下拉列表的敲除的代码。 我一点也不熟悉击倒,所以我现在能够理解它是如何工作的 所以请告诉我敲除相关代码的含义。 这是完整的代码 <p> Your country: <asp:DropDownList ID="ddlCountries" runat="server" data-bind="options: countryModel.countries, optionsValue: 'CountryID', optionsTex
<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;
}
什么是ko?
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()函数。如何自动调用函数
敲除如何填充下拉列表…它将如何理解如何填充下拉列表
请详细指导我。谢谢
什么是ko
ko
是全局敲除对象。它是在包含knockout.js
脚本时添加的。它类似于jquery的$
变量
似乎self.addCountry=function(){addCountry在调用DropDownModel()函数时会自动触发。如何自动调用函数
此函数不是自动调用的。相反,它已通过以下命令连接到“添加”按钮
<input type="button" value="Add" data-bind="click: addCountry" />
您可以找到每个选项
特定绑定值的文档
你也可以在.上找到knockout的所有文档。你能告诉我knockout.js的优点是什么吗…为什么人们会使用它。我们可以使用jquery模板绑定数据,而不是使用knockout.js。那么为什么有人使用knockout.js而不是jquery模板呢?看看他们的网页,看看他们为你为什么要这么做而提出的要点uld使用它。对我来说,knockoutjs使制作交互式GUI变得更加容易。我不熟悉jquery模板,所以我无法回答这个问题。
<input type="button" value="Add" data-bind="click: addCountry" />
// Note that I removed some of the other attributes so that it is
// easier to see the knockout only attributes.
<asp:DropDownList data-bind="options: countryModel.countries, optionsValue: 'CountryID', optionsText: 'CountryName', optionsCaption: 'Choose...'">
</asp:DropDownList>