当前位置: 代码迷 >> JavaScript >> EXTJs截取字符串rowWidth : row所占的大略宽度(使用时按中文占两个字符来度量界面布局所需的宽度)
  详细解决方案

EXTJs截取字符串rowWidth : row所占的大略宽度(使用时按中文占两个字符来度量界面布局所需的宽度)

热度:356   发布时间:2012-11-07 09:56:10.0
EXTJs截取字符串rowWidth : row所占的大概宽度(使用时按中文占两个字符来度量界面布局所需的宽度)

convertSuitableString : function(labelText, rowWidth) {
var text = '';
var regChinese = /[\u4e00-\u9fa5]/;
var regUpCharacter = /[A-Z]/;
var regLowCharacter = /[a-z]/;
var regUnderLine = /[_]/;
var regModdleLine = /[-]/;
var regNumber = /[0-9]/;
var oneLinePix = 0;
var brstring = '<br>';
var inText = labelText.toString();
for (var i = 0; i < inText.length; i++) {
var current = inText.charAt(i);
if (oneLinePix >= rowWidth) {
text += '<br>';
oneLinePix = 0;
}
if (current == ' ') {
text += ' ';
oneLinePix += 1;
} else if (regChinese.test(current)) {
text += current;
oneLinePix += 2;
} else if (regUpCharacter.test(current)) {
text += current;
if (current == 'W') {
oneLinePix += 2;
} else if (current == 'J') {
oneLinePix += 1;
} else if (current == 'I') {
oneLinePix += 0.7;
} else {
oneLinePix += 1.5;
}
} else if (regLowCharacter.test(current)) {
text += current;
if (current == 'w') {
oneLinePix += 1.8;
} else if (current == 'i' || current == 'j' || current == 'l') {
oneLinePix += 0.5;
} else {
oneLinePix += 0.9;
}
} else if (regUnderLine.test(current)) {
text += current;
oneLinePix += 1.5;
} else if (regModdleLine.test(current)) {
text += current;
oneLinePix += 0.5;
} else if (regNumber.test(current)) {
text += current;
oneLinePix += 1.2;
} else {
text += current;
oneLinePix += 1.5;
}
}
return text.toString();
},
  相关解决方案