开发手册 欢迎您!
软件开发者资料库

Framework7 - 自动编译

Framework7自动编译 - 从概述,环境,布局,导航栏,工具栏,搜索栏,状态栏,侧面板,内容块,布局网格,叠加层,预加载器,进度条,列表视图,手风琴,卡片,芯片,按钮开始学习Framework7 ,动作按钮,窗体,选项卡,Swiper滑块,照片浏览器,自动完成,选择器,日历,刷新,无限滚动,消息,消息栏,通知,延迟加载,颜色主题,细线,模板概述,自动编译,Template7页面,活动状态,点击保持事件,触摸波纹。

描述

在Template7中,您可以通过在< script>中指定特殊属性来自动编译模板.标记.

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

   

Hello, my name is {{name}} and i am {{age}} years old

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

  • 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文件 :

   

Hello, my name is {{name}} and i am {{age}} years old

   

I work as {{position}} at {{company}}

    

I have a great car, it is {{vendor}} {{model}}, made in {{year}} year.

   

It has {{power}} hp engine with {{speed}} km/h maximum speed.

您还可以在应用初始化后减去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.personTemplatevar 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.carTemplatevar carHTML = Template7.templates.carTemplate({   vendor: 'Honda',   model: 'city',   power: 1200hp,   speed: 300});
COLLECT" src="//sdk.51.la/js-sdk-pro.min.js">