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执行。