如何将主干序列化形式的所有字符串元素大写

how to uppercase all the String elements of backbone serialized form

本文关键字:字符串 元素 序列化      更新时间:2023-09-26

当我提交表单时,我会将序列化的对象发送到服务器。但是在发送它之前,我需要将其所有输入元素大写。

这是我的代码片段:

submitForm: function(e) {
    e.preventDefault();
    var data = Backbone.Syphon.serialize(this);
    console.log(data);// here i need to uppercase all data elements
    this.trigger("form:submit", data);
},

我需要在将其发送到服务器而不是后端之前执行此操作。有什么解决方案可以建议吗?

如果data是一个对象数组,则需要迭代每个对象并使用方法toUpperCase(),例如:

$.each(data, function(index, value){
    console.log(value.toUpperCase());
});