且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Kendo UI javascript:远程绑定表单

更新时间:2023-10-06 23:24:10

您的文本框已绑定到username属性,但是该属性在您的视图模型上不存在,也不存在于任何地方.假设调用read()后数据源正确地拥有一个雇员,则需要提取数据并将其设置为使用如下所示的视图模型:

Your textbox is bound to a username property but this doesn't exist on your view-model, nor is it being populated anywhere. Assuming your datasource correctly holds an employee after your call to read(), you will need to extract it and set it into your viewmodel using something like this:

change: function(e) {
    var data = this.data();
    if (data.length && data.length === 1) {
        this.set("employee", data[0]);
        this.set("hasChanges", true);
    }
}

并像这样修改绑定:

<input class="form-control k-textbox" type="text" id="username"
  data-bind="value: employee.username, events: { change: change }" />

您还应该知道change事件是在其他情况下引发的,因此,例如,如果您开始使用数据源进行更新,则需要调整该代码以考虑请求的类型.有关更多信息,请参见事件文档.希望这会有所帮助.

You should also be aware that the change event is raised in other situations, so if you start using the datasource to make updates for example, you'll need to adapt that code to take account of the type of request. See the event documentation for more info. Hope this helps.