📜  Framework7-自动编译

📅  最后修改于: 2020-10-25 03:00:38             🧑  作者: Mango


描述

在Template7中,可以通过在

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

  • 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文件中使用以下模板-


 
 

应用初始化后,您还可以在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
});