目录

Framework7 - 自动编译( Auto Compilation)

描述 (Description)

在Template7中,您可以通过在

以下代码显示自动编译布局 -

<script type = "text/template7" id = "myTemplate">
   <p>Hello, my name is {{name}} and i am {{age}} years old</p>
</script> 

您可以使用以下属性初始化自动编译 -

  • type = "text/template7" - 用于告诉Template7自动编译,它是必需的脚本类型。

  • id = "myTemplate" - 模板可通过id访问,它是必需的模板ID。

对于自动编译,您需要通过传递以下参数来启用应用程序初始化 -

var myApp = new Framework7 ({
   //It is used to compile templates on app init in Framework7
   precompileTemplates: true,
});

Template7.templates/myApp.templates

初始化应用程序后,可以作为Template7.templates属性访问自动编译的模板。 它也称为myApp.templates ,其中myApp是应用程序的初始化实例。

您可以在我们的index.html文件中使用以下模板 -

<script type = "text/template7" id = "personTemplate">
   <p>Hello, my name is {{name}} and i am {{age}} years old</p>
   <p>I work as {{position}} at {{company}}</p>
</script>
<script type = "text/template7" id = "carTemplate">
   <p>I have a great car, it is {{vendor}} {{model}}, made in {{year}} year.</p>
   <p>It has {{power}} hp engine with {{speed}} km/h maximum speed.</p>
</script> 

您还可以after应用初始化after使用JavaScript访问模板 -

var myApp = new Framework7 ({
   //Tell Framework7 to compile templates on app init
    precompileTemplates: true
});
// Render person template to HTML, its template is already compiled and accessible as 
//Template7.templates.personTemplate
var personHTML = Template7.templates.personTemplate ({
   name: 'King Amit',
   age: 27,
   position: 'Developer',
   company: 'AngularJs'
});
// Compile car template to HTML, its template is already compiled and accessible as 
//Template7.templates.carTemplate
var carHTML = Template7.templates.carTemplate({
   vendor: 'Honda',
   model: 'city',
   power: 1200hp,
   speed: 300
});
↑回到顶部↑
WIKI教程 @2018