Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 限制Mustache.js标记呈现的字符数_Javascript_Mustache - Fatal编程技术网

Javascript 限制Mustache.js标记呈现的字符数

Javascript 限制Mustache.js标记呈现的字符数,javascript,mustache,Javascript,Mustache,在Mustache中有没有办法限制Mustache标签生成的字符数 乙二醇 。。。它以静默方式失败(这里可能归咎于数据对象的递归使用) 有没有人知道不使用javascript/jQuery函数就可以实现这一点的其他方法,如果可能的话,我只想使用mustach来实现它。您的函数实际上是通过两个参数来调用的:未渲染文本和可用于渲染文本的渲染函数,保持当前上下文 data = { "limitLength" : function() { return function(text

在Mustache中有没有办法限制Mustache标签生成的字符数

乙二醇

。。。它以静默方式失败(这里可能归咎于数据对象的递归使用)


有没有人知道不使用javascript/jQuery函数就可以实现这一点的其他方法,如果可能的话,我只想使用mustach来实现它。

您的函数实际上是通过两个参数来调用的:未渲染文本和可用于渲染文本的
渲染
函数,保持当前上下文

data = {
    "limitLength" : function() {
        return function(text, render) {
          return render(text).substr(0,10) + '...';
        }
      },
     "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
}

你是对的,这很有效,谢谢……但是你怎么知道它是这样工作的呢?位于的Mustache文档似乎不完整,因为没有提及该函数的此渲染参数。我是否还缺少其他更全面的文档,或者您只是在Mustach.js库中查找来发现这一点?在任何情况下,这些文件都应该得到纠正。我在github上创建了一个问题。我不记得是在哪里发现的,但是mustache.js的自述文件确实提到了它。+1用于制作一个带有
函数(文本、渲染)
的示例。。由于mustache 5文档遗漏了
,渲染
部分,您解决了我的问题!
template = "<li>{{#limitLength}}{{my_tag}}{{/limitLength}}</li>"

data = {
    "limitLength" : function() {
        return function(text) {
          return text.substr(0,10) + '...';
        }
      },
    "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
}
data = {
    "limitLength" : function() {
        return function(text) {
          return Mustache.to_html(text,data).substr(0,10) + '...';
        }
      },
     "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
}
data = {
    "limitLength" : function() {
        return function(text, render) {
          return render(text).substr(0,10) + '...';
        }
      },
     "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
}