Bind data to content element in Polymer

痴心易碎 提交于 2020-01-05 02:55:10

问题


I wanted to ask if it is possible to bind data to the element and access it later inside the actual content. Here is an example: I want to create a list component, however let the user define how to render every entry. Here is my current code:

List Element:

<template repeat="{{item in items}}">
  <content></content>
</template>

User using it:

<ak-list items="{{items}}">
  {{item.name}}
</ak-list>

However, this does not work


回答1:


I suppose - you won't get access to data model from inside HTML portion in the web components.

You need to be defining the data in the template. I guess you might be already aware of that.

http://jsbin.com/yadazo/1/edit?html,output

A bin with how it could work.

Also, you can control the presentation by passing in an additional data which you can then use in your template -

An example of the same is below. -

http://jsbin.com/yateka/1/edit?html,output

both the list and how you want it can be supplied and then template created with that stuff.



来源:https://stackoverflow.com/questions/26369519/bind-data-to-content-element-in-polymer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!