ExtJs: TextArea 如何将 return 值作为数组而不是字符串?
ExtJs: TextArea how to return value as an array instead of as a string?
在 ExtJs 6.2 上,我有一个带有 TextArea 的表单。
当用户在多行中输入文本时,例如:
line 1
line 2
绑定值目前是一个字符串:
value= "line 1↵line 2"
但是我需要在商店提交时将值作为数组发送(到服务器)。
如何告诉文本区域 return 输入文本作为数组?
value : ["line1", "line2"]
无需在服务器端将字符串拆分为数组。
编辑:我不想只是分割价值。因为我想更新文本区域的默认行为以避免每次使用它时都必须应用拆分(在 ViewController 中)。
document.getElementById('textarea').value.split('↵')
你可以使用sencha提供的标准方式http://docs.sencha.com/extjs/5.0.0/api/Ext.form.field.TextArea.html#placeholder-simple-getValue
检查并回复。
我已经创建了一个 fiddle 我将如何处理它(假设我已经正确理解你的要求!)
https://fiddle.sencha.com/#view/editor&fiddle/1uq7
此示例在进入文本区域时将数组转换为字符串,并在离开时将其拆分。
Ext.define('ArrayTextArea', {
extend: 'Ext.form.field.TextArea',
alias: 'widget.arraytextarea',
setValue: function(val){
// if it's an array then join with a newline
if(Ext.isArray(val)){
val = val.join('\n');
}
return this.callParent([val]);
},
getValue: function(){
var val = this.callParent(arguments);
// split the value by newline char
return val.split('\n');
}
});
在 ExtJs 6.2 上,我有一个带有 TextArea 的表单。 当用户在多行中输入文本时,例如:
line 1
line 2
绑定值目前是一个字符串:
value= "line 1↵line 2"
但是我需要在商店提交时将值作为数组发送(到服务器)。
如何告诉文本区域 return 输入文本作为数组?
value : ["line1", "line2"]
无需在服务器端将字符串拆分为数组。
编辑:我不想只是分割价值。因为我想更新文本区域的默认行为以避免每次使用它时都必须应用拆分(在 ViewController 中)。
document.getElementById('textarea').value.split('↵')
你可以使用sencha提供的标准方式http://docs.sencha.com/extjs/5.0.0/api/Ext.form.field.TextArea.html#placeholder-simple-getValue 检查并回复。
我已经创建了一个 fiddle 我将如何处理它(假设我已经正确理解你的要求!)
https://fiddle.sencha.com/#view/editor&fiddle/1uq7
此示例在进入文本区域时将数组转换为字符串,并在离开时将其拆分。
Ext.define('ArrayTextArea', {
extend: 'Ext.form.field.TextArea',
alias: 'widget.arraytextarea',
setValue: function(val){
// if it's an array then join with a newline
if(Ext.isArray(val)){
val = val.join('\n');
}
return this.callParent([val]);
},
getValue: function(){
var val = this.callParent(arguments);
// split the value by newline char
return val.split('\n');
}
});