我只是Kendo-UI的初学者。查找所有文档,我无法得到我的问题的答案或示例。 我试图通过kendo.observable和kendo.data.DataSource将mysql表绑定到表单。
我的Html:
<body>
<div id="example">
<ul id="fieldlist">
<li><label for="fname">First Name:</label> <input id="fname" data-bind="value: patientname" class="k-textbox" /></li>
</ul>
</div>
</body>
我的JS:
<script>
fenotypSource = new kendo.data.DataSource({
transport: {
read: {url: function(){return "data_json/fenotyp_read.php?idpacjenta=1"}}
}
});
viewModel = kendo.observable({
data: fenotypSource
});
kendo.bind($("#example"), viewModel);
fenotypSource.read();
</script>
我的JSON我从fenotyp_read获得的内容: {id:“1”,idpatient:“1”,病名:“Smith”}
我收到错误:TypeError:e.slice不是函数 比你所有的帮助。
答案 0 :(得分:0)
您没有必要为此提供Kendo UI DataSource。您可以使用单个ObservableObject将特定对象绑定到表单。看看我为你制作的样本here。
<body>
<script>
$(document).ready(function(){
// you can use simple ajax request to get remote data
// and bind result to observable viewModel
/*
$.ajax({
method: "POST",
url: "data_json/fenotyp_read.php?idpacjenta=1",
}).done(function( data ) {
var patient = new kendo.data.ObservableObject( data );
viewModel.set("patient", patient);
});
*/
// this is local data to demonstrate ObservableObject
var data = new kendo.data.ObservableObject({
id: "1",
idpatient: "1",
patientname: "Smith"
});
var viewModel = kendo.observable({
patient: data
});
kendo.bind($("#example"), viewModel);
});
<form id="example">
<label>Id:</label><span data-bind="text: patient.idpatient"> </span>
<br/>
<label>Patient Name:</label><input class="k-textbox" type="text" data-bind="value: patient.patientname"/>
</form>
</body>