Framework7 - 直接加载模板
说明
您还可以将模板作为动态页面动态渲染和加载。以下代码演示了如何使用模板作为动态页面 −
index.html
<script type = text/template7" id = about"> <div class = pages"> <div data-page = about" class = page"> <div class = page-content"> <div class = content-block"> <div class = content-block-inner"> <p>Hello, i am <b>{{firstname}} {{lastname}}</b>, <b>{{age}}</b> years old and working as <b>{{position}}</b> at <b>{{company}}</b>.</p> </div> </div> </div> </div> </div> </script>
所需数据从 template7Data 中获取。要指定所需模板,您需要使用带有模板 ID 的 data-template 属性。
您可以使用 JavaScript View 的 .load () 方法和 template 属性传递自定义数据,如以下实例所示 −
mainView.router.load ({ template: Template7.templates.aboutTemplate, context: { firstname: 'William', age: 27 } })
framework7_template7_pages.html