Skip to content

Instantly share code, notes, and snippets.

@LaleWolf
Created October 3, 2012 08:35
Show Gist options
  • Save LaleWolf/3825814 to your computer and use it in GitHub Desktop.
Save LaleWolf/3825814 to your computer and use it in GitHub Desktop.
Anpassung des ListModels auf KendoUI Grid Column Struktur
_.mixin({
renameProperties: function (object, translations) {
_.each(_.pairs(translations), function(translation) {
_.each(object, function(item){
if (item.hasOwnProperty(translation[0])) {
item[translation[1]] = item[translation[0]];
delete item[translation[0]];
}
return item;
});
});
return object;
}
});
ListModel
"columns": [{
"name": "GUID",
"label": "Guid",
"datatype": "GuidString"
}, {
"name": "DESCRIPTION",
"label": "Description",
"datatype": "String"
}],
zu
columns:[
{
field: "FirstName",
title: "First Name"
},
{
field: "LastName",
title: "Last Name"
}],
Object.prototype.renameProperty = function (oldName, newName) {
// Check for the old property name to avoid a ReferenceError in strict mode.
if (this.hasOwnProperty(oldName)) {
this[newName] = this[oldName];
delete this[oldName];
}
return this;
};
Array.prototype.renameProperties = function (oldName, newName) {
_.each(this, function (elem) {
elem.renameProperty(oldName, newName);
};
return this;
};
_.mixin({
renameProperties: function (object, oldValue, newValue) {
_.each(object, function(item) {
item.renameProperty(oldValue, newValue);
});
return object;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment