polymer-quick tour of polymer

注册一个元素

<link rel="import"
      href="bower_components/polymer/polymer.html">//没有添加<dom-module>
<script>
Polymer({
  is:‘proto-element‘,
  ready:function(){
    this.innerHTML=‘sfp‘;
  }
})
</script>

增加本地元素:在<template>中

<link rel="import"
      href="bower_components/polymer/polymer.html">

<dom-module id="dom-element">
  <template>
    <p>I‘m a DOM element. This is my local DOM!</p>
  </template>
</dom-module>

<script>
  Polymer({
    is: "dom-element",
  });
</script>

本地元素布局:在main中

<link rel="import"
      href="bower_components/polymer/polymer.html">

<dom-module id="picture-frame">
  <!-- scoped CSS for this element -->
  <style>
    div {
      display: inline-block;
      background-color: #ccc;
      border-radius: 8px;
      padding: 4px;
    }
  </style>
  <template>
    <div>
      <!-- any children are rendered here -->
      <content></content>
    </div>
  </template>
</dom-module>

<script>
  Polymer({
    is: "picture-frame",
  });
</script>
<!DOCTYPE html>
<html>
  <head>
    <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
    <link rel="import" href="picture-frame.html">
  </head>
  <body>
    <picture-frame>
      <image src="images/p-logo.svg">
    </picture-frame>
  </body>
</html>

数据绑定:在Polymer()中定义数据,在<template>中显示

<link rel="import"
      href="bower_components/polymer/polymer.html">

<dom-module id="name-tag">
  <template>
    <!-- bind to the "owner" property -->
    This is <b>{{owner}}</b>‘s name-tag element.
  </template>
</dom-module>

<script>
  Polymer({
    is: "name-tag",
    ready: function() {
      // set this element‘s owner property
      this.owner = "Daniel";
    }
  });
</script> 

声明properties:看起来跟数据绑定功能类似,其实是要序列化为attribute;声明attribute,用hostAttributes

<link rel="import"
      href="bower_components/polymer/polymer.html">

<dom-module id="configurable-name-tag">
  <template>
    <!-- bind to the "owner" property -->
    This is <b>{{owner}}</b>‘s configurable-name-tag element.
  </template>
</dom-module>

<script>
  Polymer({
    is: "configurable-name-tag",
    properties: {
      // declare the owner property
      owner: {
        type: String,
        value: "Daniel"
      }
    }
  });
</script>

绑定properties:把定义的值传给属性

<link rel="import"
      href="bower_components/polymer/polymer.html">
<dom-module id=‘proto-element‘>
  <style>
  div{
    width:100px;
    height:100px;
    background-color:olive;
  }
  </style>
  <template>
    <div>
      <p id=‘{{owner}}‘>local dom</p>
      <content></content>
    </div>
  </template>
</dom-module>
<script>
Polymer({
  is:‘proto-element‘,
  properties:{
    owner:{
      type:String,
      value:‘bind properties‘
    }
  }

})
</script>

  

  

时间: 2024-11-08 02:30:17

polymer-quick tour of polymer的相关文章

【转】Polymer API开发指南 (二)(翻译)

原文转自:http://segmentfault.com/blog/windwhinny/1190000000596258 公开 property 当你公开一个 Polymer 元素的 property 名字时,就等于把这个 property 设置为公开API了.公开 property 会有如下的特性: 支持声明数据双向绑定 通过声明,property 将会按照名称一样的 html attribute 初始化数据 property 的值可以反射到元素对应的attribute上 注: proper

netty Getting Started--reference

reference from:http://docs.jboss.org/netty/3.1/guide/html/start.html 1.1. Before Getting Started 1.2. Writing a Discard Server 1.3. Looking into the Received Data 1.4. Writing an Echo Server 1.5. Writing a Time Server 1.6. Writing a Time Client 1.7.

麦子学院-Web前端开发工程师系列培训教程

HTML+CSS基础入门1.课程介绍2.html的语法3.html的基本结构4.html的文档设置标记上(格式标记)5.html的文档设置标记下(文本标记)6.html图像标记img7.html超链接的使用8.html表格相关的标记9.html表格实战<简单的网页布局>10.html框架详解与框架布局实战11.HTML表单设计(上)12.HTML表单设计(下)13.使用CSS样式的方式14.定义CSS样式(CSS选择器)15.CSS常用属性(颜色属性)16.css常用属性(字体相关属性)17.

Chapter 10-02

Please indicate the source: http://blog.csdn.net/gaoxiangnumber1 Welcome to my github: https://github.com/gaoxiangnumber1 10.4 工程项目中头文件的使用规则 10.4.1 头文件的害处 ?我认为头文件的害处主要体现在以下几方面: 1.传递性. 头文件可以再包含其他头文件.一个简单的#include 展开之后有两万多行代码,一方面造成编译缓慢:另一方面,任何一个头文件改动一点

Why malloc+memset is slower than calloc?

https://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc/ The short version: Always use calloc() instead of malloc()+memset(). In most cases, they will be the same. In some cases, calloc() will do less work because it can sk

【NS2】NS2 教學手冊(转载)

之前做毕设的时候搜索NS2的相关资料,发现这个里面涵盖很广,特此收藏,感谢原作者的辛勤劳作. NS2 教學手冊 ( NS2 Learning Guide) [快速連結區] My works  中文影音教學區  Q&A for my works  My Book  My Talks  Forum  Basic  ns2-installation  Tcl/Tk/Otcl  Debug  Trace Processing  awk/gawk  Gnuplot  perl  latex  Traffi

object -c OOP , 源码组织 ,Foundation 框架 详解1

?object -c? OOP ,??源码组织??,Foundation?框架?详解1 1.1 So what is OOP? OOP is a way of constructing software composed of objects. Objects are like little machines living inside your computer and talking to each other to get work done. oop?就是由对象构成的软件. 对象就像一些

MongoDB for Java入门

Introduction This page is a brief overview of working with the MongoDB Java Driver. For more information about the Java API, please refer to the online API Documentation for Java Driver. A Quick Tour Using the Java driver is very simple. First, be su

Spring AMQP 源码分析 04 - MessageListener

### 准备 ## 目标 了解 Spring AMQP 如何实现异步消息投递(推模式) ## 前置知识 <RabbitMQ入门_05_多线程消费同一队列> ## 相关资源 Quick Tour for the impatient:<http://docs.spring.io/spring-amqp/docs/1.7.3.RELEASE/reference/html/_reference.html#async-consumer> Sample code:<https://git