javascript - 如何利用polymer 给模板中的元素附上自定义属性?
大家讲道理
大家讲道理 2017-04-10 16:36:11
0
1
268
<dom-module id="geo-comtoolbar">
    <template>
        <ul class="toolBarWrap" id="toolWrap">
            <template is='dom-repeat' items={{toolName}}>
                <li tooltype='{{item.tooltype}}'>
                    <img src="{{item.imgUrl}}">
                    <span>{{item.tName}}</span>
                </li>
            </template>
        </ul>
    </template>
</dom-module>

<script type="text/javascript">
    Polymer({
        is: 'geo-comtoolbar',

        ready: function (){
            this.toolName = [
                {tName: '平移', imgUrl: 'imgs/maptool/drag.png', tooltype: 'pan'},
                {tName: '距离', imgUrl: 'imgs/maptool/distance.png', tooltype: 'calLen'},
                {tName: '面积', imgUrl: 'imgs/maptool/area.png', tooltype: 'calArea'}
            ];

        },    
    });
</script>

刚研究polymer,为每个li绑定tooltype属性,用{{item.tooltype}}解析不了。是不是可以用其他的方式?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
阿神

我是把repeat item也定义成组件了。

<template is="dom-repeat" items="{{testItems}}">
    <performance-item item="{{item}}"></performance-item>
</template>
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="performance-item">
    <template>
        <li>
            <p>
                <label>{{item.field}}</label>
                <input type="text" value="{{item.field::input}}" style="width:80px">
            </p>
       </li>
    </template>
    <script>
        Polymer({
            is: "performance-item",
            properties:{
                item:{
                    value: null,
                    type: "object"
                }
            }
        });
    </script>
</dom-module>

题主有兴趣,可以看下我写的polymer几篇专栏,虽然都比较浅

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!