[英]Object literal in filter function
I have my filter configured like this,and I need to pass the filter object in a dinamic way. 我已将过滤器配置为这样,并且需要以动态方式传递过滤器对象。
filter: function ( response ) {
return $.map(response,function (object) {
return {
value: object.descricaoMunicipio,
municipioId: object.municipioId,
descricaoMunicipio: object.descricaoMunicipio,
id: object.municipioId
};
});
}
I need to pass the return in a generic way,like this:Is it possible? 我需要以一种通用的方式传递退货,就像这样:有可能吗?
var fnc = {
value: object.uf.descricaoUf,
municipioId: object.municipioId,
descricaoMunicipio: object.uf.descricaoUf,
id: object.municipioId
}
filter: function ( response ) {
return $.map(response,function (object) {
return {
eval(fnc)
};
});
}
You can define a named that does what you want: 您可以定义一个您想要的名称:
var fnc = function(object) {
return {
value: object.uf.descricaoUf,
municipioId: object.municipioId,
descricaoMunicipio: object.uf.descricaoUf,
id: object.municipioId
};
}
And then use it like this: 然后像这样使用它:
filter: function(response) {
return $.map(response, function (object) {
return fnc(object);
});
}
Or you can just write: 或者您可以只写:
filter: function(response) {
return $.map(response, fnc);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.