我已经成功地使用JSON和Kendo.Observable构建了一个动态表单,但是我无法在同一个JSON中成功地初始化下拉列表值。唯一能让它工作的方法是在创建后将下拉列表绑定到单独的json请求。见下面的例子..。
下面是一个可以工作的JSON示例(没有下拉列表)
{"fields": [
{"name" : "FirstName", "label" : "First Name", "type" : "text", "css" : "test"},
{"name" : "LastName", "label" : "Last Name", "type" : "text", "css" : "test"},
{"name" : "Email", "label" : "Email", "type" : "text", "css" : "test"},
{"name" : "Phone", "label" : "Phone", "type" : "text", "css" : "test"},
{"name" : "Subscribed", "label" : "Subscribed", "type" : "checkbox", "css" : "test"}
]}下面是一个示例,我添加了一个下拉列表,不打算发布全部内容,我尝试了下面的一些不同的变体来尝试填充select,但是找不到任何工作。
{"fields": [
{"name" : "Email", "label" : "Email", "type" : "text", "css" : "test"},
{"name" : "FirstName", "label" : "First Name", "type" : "text", "css" : "test"},
{"name" : "LastName", "label" : "Last Name", "type" : "text", "css" : "test"},
{"name" : "Company", "label" : "Company", "type" : "text", "css" : "test"},
{"name" : "ddlCountry", "label" : "Country", "type" : "select", "dataTextField" : "text", "dataValueField" : "value", "dataSource":[{"text" : "AF","value" : "Afghanistan"},{"text" : "AL","value" : "Albania"},{"text" : "DZ","value" : "Algeria"},{"text" : "AS","value" : "American Samoa"},{"text" : "AD","value" : "Andorra"},...etc...下面是绑定它的脚本
$.ajax({
url: "http://localhost/go/getformjson",
type: "GET",
dataType: "json",
success: function (model) {
// convert the JSON to observable object
var viewModel = kendo.observable(model);
// bind the model to the container
kendo.bind($("#example"), viewModel);
}
});发布于 2014-04-22 14:45:34
您需要指定数据文本字段和数据值字段属性:
<select data-bind="source: options" data-text-field="ddltext" data-value-field="ddlvalue" />以下是您的小提琴的更新版本:http://jsfiddle.net/aUAJv/64/
https://stackoverflow.com/questions/23145505
复制相似问题