从剑道下拉列表中删除下划线
Remove underscore from Kendo dropdownlist
这个看起来很简单,只是不知道在哪里处理它。我正在通过 REST JSON 从 SQL 数据库中检索列名值。下拉列表中的值具有预期下划线 (Customer_Name)。我想显示不带下划线的"友好"(客户名称)版本,但仍将我的值 (Customer_Name) 发送到我的 REST 服务。我看了下划线.js但只是不知道从哪里开始,这可能比我想象的要简单。谢谢!
我不知道
您如何从休息服务接收数据。
但基本上,您只需要映射 REST 服务接收的数据,根据需要更改值。
下面是一些示例代码:
// Call to the REST service and when done call the callback function loadDDL
$.ajax({
type: "POST",
url: "my-rest-service"
}).done(loadDDL);
// Callback function when returning from the REST service
// -> load data in the DDL (here, it has the id "my-ddl")
function loadDDL(data) {
$("#my-ddl").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: _.map(data, makeFriendlyName),
index: 0
});
}
// Function used by the _.map function in order
// change dynamically the labels in the DDL
function makeFriendlyName(obj) {
return {
text: obj.text,
value: obj.value.replace("_", " ")
};
}
编辑:
基于OP的小提琴,下面是一个使用模板而不是直接更改数据源的示例代码:
function loadDDL(data) {
$("#my-ddl").kendoDropDownList({
autoBind: true,
dataTextField: "DOMAINQUERY",
dataValueField: "COLUMN_NAME",
dataSource: dataSourceSearch1,
template: "${DOMAINQUERY.replace(/_/g, ' ')}"
});
}
编辑 2 :
为了直接翻译数据源,我再次通过动态更改数据源change
事件中的文本来重新映射数据源:
var dataSourceSearch1 = new kendo.data.DataSource({
transport: {
read: {
url: "http://demos.kendoui.com/service/Customers",
dataType: "jsonp"
}
},
change: changeDS // <-- Here add a change event : each time the datasource changes, this event is being raised
});
// This is the function call when the DS changes
// the data stuff is in the `items` property which is the object send via the REST service
function changeDS(datasource) {
_.map(datasource.items, makeFriendlyName);
}
// Function to apply to each data -> here I just replace all spaces in the
// `ContactName` field by `_`
function makeFriendlyName(data) {
data.ContactName = data.ContactName.replace(/ /g, '_');
return data;
}
// Fill the DDL with the previous datasource
var cboSearchField1 = $("#cboSearchField1").kendoDropDownList({
dataTextField: "ContactName",
dataValueField: "ContactName",
filter: "contains",
autobind: true,
select: cboSearchField1_Selected,
change: cboSearchField1_onChange,
dataSource: dataSourceSearch1
}).data("kendoDropDownList");
相关文章:
- 下划线用句点扩展.旋转引号被删除,如何用引号获得它
- 下划线.js,根据键值删除对象数组中的重复项
- 如何删除列表中的对象?Javascript nodejs和下划线
- 单击时删除下划线(函数()
- 删除下划线后的字符串
- 我在angular JS中选择了一个默认选项,并删除了两个单词之间的下划线
- 从对象数组中删除重复项 - 下划线
- 当处于活动状态时,我如何删除文本修饰.我有以下代码,但链接带有下划线
- 从剑道下拉列表中删除下划线
- 如何使用下划线从对象内的数组中删除空的、空的、未定义的值
- 如何在具有某些条件的情况下从列表中删除重复项,下划线.js
- j查询更改/删除导航链接上的下划线
- 从带有下划线的数组中删除项目.js
- 使用 JavaScript 的下划线删除重复对象
- 在JavaScript中使用Regex删除下划线
- 如何从正则表达式[^wxC0-xFF]中删除空格和下划线
- ExtJS如何在选中并覆盖时删除网格行下划线
- 如何使用下划线.js或 jquery 删除模式
- 删除下划线.js中的当前对象each()或other
- 删除下划线格式