input type="checkbox" class="btn pointCheck"
id="GasMeteringVC-VolumeCorrector-Temperature t"
value="GasMeteringVC/VolumeCorrector/Temperature t">
<label for="GasMeteringVC-VolumeCorrector-Temperature t" class="pointBefore"></label>
有人可以帮我删除温度和t之间的空白。
<input type="checkbox" class="btn pointCheck" id="{{../../name}}-{{../name}}-{{name}}"
value="{{../../name}}/{{../name}}/{{name}}"/>
<label for="{{../../name}}-{{../name}}-{{name}}" class="pointBefore">
上面是把手代码,它生成一个带有复选框和标签的菜单。所有值都来自JSON对象。
答案 0 :(得分:0)
如前所述,最好在模板外进行此类清洁。但是,如果您选择使用该路线,则可以使用助手。
Handlebars.registerHelper('cleanConcat', function() {
var argument = null;
var data = null;
var cleanedString = '';
var cleanedStrings = [];
for ( var i = 0; i < arguments.length; ++i ) {
argument = arguments[ i ];
// Handlebars passes in extra arguments, so you can't just loop through
// arguments itself
if ( typeof argument === 'object' && argument.name === 'cleanConcat' ) {
data = argument.data.root;
for ( var prop in data ) {
// You can do any type of cleaning that you want here.
// As an example I forced each string to lower case and replaced spaces with a "-"
cleanedString = data[ prop ].toLowerCase().replace( /\s/g, '-' );
cleanedStrings.push( cleanedString );
}
return cleanedStrings.join( '-' );
}
}
});
<label for="{{cleanConcat ../../name ../name name}}"