在您第一个指向 kendo dojo 的链接中,在viewModel
i 内部创建一个包含 ajax 调用以从后端检索值的函数
getData: function () {
$.ajax({
url: "http://demos.telerik.com/kendo-ui/service/Products", //replace this with your url to get the data from backend
type: "GET",
dataType: "jsonp" // replace this with the type suit your need maybe json or etc (just use this as example to fire the success event
}).success(function (data) {
//asumme this dummy data is the data coming from backend
var dummyData = {
textValue: "new Text value",
textareaValue: "new Textarea value",
checkboxValue: true,
radioValue: "new Apple",
checkboxListValue: ["Banana"],
multipleSelectValue: ["Banana"],
fruits: ["Apple", "Banana", "Orange"],
selectValue: "Orange"
};
//set the viewModel value with the data coming from backend
viewModel.set("textValue", dummyData.textValue);
viewModel.set("textareaValue", dummyData.textareaValue);
viewModel.set("checkboxValue", dummyData.checkboxValue);
viewModel.set("radioValue", dummyData.radioValue);
viewModel.set("checkboxListValue", dummyData.checkboxListValue);
viewModel.set("multipleSelectValue", dummyData.multipleSelectValue);
viewModel.set("selectValue", dummyData.selectValue);
//after you set the value, because the viewModel already bind with the component/value of the kendo widget on the HTML side the textbox/dropdown/checkbox will automatically updated
});
}
我还在 html 上创建了一个按钮来触发 getData 函数
<tr>
<td><span data-role="button" data-bind="events:{click:getData}" />
<h4>Click this to do ajax call </h4>
</td>
</tr>
看到这个道场,点击按钮,你会看到数据从(文本值到新文本值)更新