mustache学习补遗

mustache.txt

是非判断

{"repos": []}



{{#repos}}<b>{{name}}</b>{{/repos}}

{{^repos}}No repos :({{/repos}}



No repos :(

.=this

{ "musketeers": ["Athos", "Aramis", "Porthos", "D'Artagnan"]}



{{#musketeers}}

* {{.}}

{{/musketeers}}



* Athos

* Aramis

* Porthos

* D'Artagnan

自动向上匹配数据源的方法

{

  "beatles": [

    { "firstName": "John", "lastName": "Lennon" },

    { "firstName": "Paul", "lastName": "McCartney" },

    { "firstName": "George", "lastName": "Harrison" },

    { "firstName": "Ringo", "lastName": "Starr" }

  ],

  "name": function () {

    return this.firstName + " " + this.lastName;

  }

}



{{#beatles}}

* {{name}}

{{/beatles}}



* John Lennon

* Paul McCartney

* George Harrison

* Ringo Starr

支持子属性

{

  "name": {

    "first": "Michael",

    "last": "Jackson"

  },

  "age": "RIP"

}



* {{name.first}} {{name.last}}

* {{age}}



* Michael Jackson

* RIP

你可能感兴趣的:(mustache)