New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

arale-templatable

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arale-templatable

处理组件的模板渲染,混入到 Widget 中使用。

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
6
Weekly downloads
 
Created
Source

Templatable


spm package Build Status Coverage Status

处理组件的模板渲染,混入到 Widget 中使用。


使用说明

可混入的功能类,提供 Handlebars 模板支持。

var Templatable = require('templatable');

var MyWidget = Widget.extend({
    Implements: Templatable
});

var myWidget = new MyWidget({
    template: '<div><h3>{{title}}</h3><ol>{{#each list}}<li>{{item}}</li>{{/each}}</div>',
    model: {
        'title': '标题',
        'list': [
            { 'item': '文章一' },
            { 'item': '文章二' }
        ]
    },
    parentNode: '#demo'
});

myWidget.render();

Templatable 在渲染的时候会读取 this.get('model')this.get('template'),这两个是实例化的时候传入的,最终生成 this.element

this.get('template') 支持多种格式:

  1. html 的字符串

  2. id 选择器,最常用而且判断简单

  3. 函数,通过 handlerbars 编译过的模板

renderPartial .renderPartial(selector)

局部渲染,根据传入的 selector 参数,刷新匹配的区域。

默认无需覆盖。需要覆盖时,请使用 return this 来保持该方法的链式约定。

this.set('model', {
  title: '新标题'
});
this.renderPartial('h3');

templateHelpers

可以使用 handlebars 的 helper,由于 handlerbars 是全局注册,所以每次编译都会重新注册。

示例二

templatePartials

可以使用 handlebars 的 partials。

Keywords

FAQs

Package last updated on 23 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc