English 中文(简体)
限制Mustache.js tag提供的特性数量
原标题:Limit the number of characters rendered by a Mustache.js tag

Mustache是否以任何方式限制Mustache tag的特性数量?

页: 1

template = "<li>{{my_tag}}</li>"

data = {
    "my_tag" : "A very long string that needs to be abbreviated to fit into the available space."
}

Now when I render my tag I want to abbreviate the long string by showing only the first 10 chars follwed by an ellipsis. I looked into using a lambda function (as described in the Mustache docs) like so...

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."
}

但不幸的是,Petmy-tag 并没有扩大。 《Mustache手册》指出:

The text passed is the literal block, unrendered. {{tags}} will not have been expanded - the lambda should do that on its own.

.. but I can t imagine how to do this without using the Mustache.to_html() function and when I try to use it like so...

页: 1

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."
}

......它没有保持沉默(重复使用数据标本可能会在这里被指责)

是否有任何人知道在不行使 j/Qu职能的情况下实现这一点的其他任何方式,我希望在可能时使用Mustache执行。

最佳回答

您的职能实际上有两种论点:未经提交的文本和<编码>render功能,可用来使案文成为原文,保持目前的情况。

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."
}
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签