Nan*_*ner 8 jquery datasource autocomplete concatenation kendo-ui
我想为Kendo自动完成的dataTextField属性组合两个字段.
我的数据有一个FirstName字段和一个LastName字段.
schema: {
data: "d",
model: {
id: "PersonId",
fields: {
PersonId: {
type: "number",
editable: false // this field is not editable
},
FirstName: {
type: "text",
validation: { // validation rules
required: true // the field is required
}
},
LastName: {
type: "text",
validation: { // validation rules
required: true // the field is required
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法可以配置自动完成以显示FirstName + LastName?
也许我必须对数据源做一些事情,如果是这样的话,有人可以提供一个简单的例子吗?
谢谢!
你应该使用模板:
例如:
template:"The name is : #= FirstName # #=LastName #"
Run Code Online (Sandbox Code Playgroud)
使用模板是一种有效的解决方案 但是,如果要始终在模型上访问复合或计算字段,则可以在模式定义中定义解析函数.
schema: {
data: "d",
model: {
id: "PersonId",
fields: {
PersonId: {
type: "number",
editable: false // this field is not editable
},
FirstName: {
type: "string",
validation: { // validation rules
required: true // the field is required
}
},
LastName: {
type: "string",
validation: { // validation rules
required: true // the field is required
}
},
Name: {
type: "string"
// add any other requirements for your model here
}
}
},
parse: function (response) {
var values = response.d,
n = values.length,
i = 0,
value;
for (; i < n; i++) {
value = values[i];
value.Name = kendo.format("{0} {1}",
value.FirstName,
value.LastName);
}
return response;
}
}
Run Code Online (Sandbox Code Playgroud)
解析函数在使用服务器响应之前对其进行预处理,因此您可以修改现有字段或附加新字段.然后,您可以直接在使用模型的任何控件中引用字段.