Javascript js-引用具有特定索引的项

Javascript js-引用具有特定索引的项,javascript,mustache,hogan.js,Javascript,Mustache,Hogan.js,我希望只为数组中的特定项创建一个节。例如: var items = ['first','second'] 例如: 我试过: {{#items.1}} Slightly different styling for the second item, for no difference other than it's the second item. {{/items.1}} 以及: {{#items}} {{#0}} Slightly different styling for

我希望只为数组中的特定项创建一个节。例如:

var items = ['first','second']
例如:

我试过:

{{#items.1}}
  Slightly different styling for the second item, for no difference other than it's the second item.
{{/items.1}}
以及:

{{#items}}
  {{#0}}
     Slightly different styling for the second item, for no difference other than it's the second item.
  {{/0}}
{{/items}}
但这两种方法都不管用

我真的不想制作这样的对象:

{'1':'first','2':'second'}
因为那太恶心了


有什么想法吗?

在我给你一些建议/解决方法之前 就像您所说的,它只是一些愚蠢的样式,因此与渲染或数据无关。如果它在这个意义上有意义,您应该将其添加到数据中,以便更好地表示ts结构

Mustache是一种无逻辑的模板语言,如果您觉得需要使用Mustache语言,您应该尽可能减少它的逻辑性,否则只需使用手柄即可

css 你可以使用css
为此,;虽然我不想得到全面的答案!我转向express3车把,它给了我与hogan相同的功能,就像是一个临时替代品。尝试它,我实际上意识到车把不是一个解决方案:{{@index}}只是用于循环,我不想看,只是字面上有一个只针对第2项的部分。@Naller和我刚刚意识到,你的意思可能是你只想要列表中的第二项,但不太灵活,只需要在TemplatesHanks之外解决它。有没有办法创建一个接受参数的助手?我不想为每个索引创建一个新的帮助器。@Naller当然,但是,为什么不循环;如果您不担心性能,那么循环很可能更快,编译模板是大部分工作
{'1':'first','2':'second'}
.selector:nth-child(2) {
    some: styling;
}
var items = ['first','second'];
var data = {items:items};

data.second= (function () {
    var i=0;
    return function () {
        return i++ === 1; //index 1 being the second item in an array
    }
}());
{{#items}}
    {{#second}}
    Slightly different styling for the second item, for no difference other than it's the second item.
    {{/second}}
{{/items}}