限制字符长度以在带有把手的jquery表中显示

use*_*914 2 handlebars.js

如何使用从中填充的jqurty表来限制要显示的字符 Handlerbars.Compile

Handlebars.compile('<tr><td>{{productDescription}}</td></tr>')
Run Code Online (Sandbox Code Playgroud)

我想只显示前10个字符,并希望显示...用户点击哪个字符应该调用显示整个产品描述的jqueryui对话框.

tsi*_*iki 9

使用Handlebars助手:

Handlebars.registerHelper('dotdotdot', function(str) {
  if (str.length > 10)
    return str.substring(0,10) + '...';
  return str;
});
Run Code Online (Sandbox Code Playgroud)

之后,在你的模板中写

{{dotdotdot productDescription}}
Run Code Online (Sandbox Code Playgroud)