在 immutableJS 中,我试图将输出输出到 .
name: "此字段为必填项。另一个错误。", age: "只允许使用数字字符。"
const Immutable = require("immutable");
let error = Immutable.fromJS({
name: ["This field is required", "Another error"],
age: ["Only numeric characters are allowed"]
});
最佳答案
ONELINER:就地(对 this version of question 的回答 - 示例)
Object.entries(error).map( x=> error[x[0]] = x[1].join('. ')+'.' );
let error = {
name: ["This field is required", "Another error"],
age: ["Only numeric characters are allowed"]
};
Object.entries(error).map(x=>error[x[0]]=x[1].join('. ')+'.');
console.log(error);
通过这种方式,您可以将其包装在函数中(不可变):
let var func = (e,r={})=>(Object.entries(e).map(x=>r[x[0]]=x[1].join('. ')+'.'),r);
let result = func(error) // run it in this way
关于javascript - Immutable.JS 联系和修改输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53820878/