将数据绑定到Polymer中的内容元素 [英] Bind data to content element in Polymer

查看:90
本文介绍了将数据绑定到Polymer中的内容元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想询问是否可以将数据绑定到元素,并在稍后在实际内容中访问它。这里是一个例子:我想创建一个列表组件,但是让用户定义如何呈现每个条目。这是我现在的代码:

列表元素:



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



使用它的用户:



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

然而,这不起作用

解决方案

我想 - 您将无法从Web组件的HTML部分访问数据模型。

您需要在模板中定义数据。我想你可能已经意识到了这一点。



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



它可以如何工作。



另外,您可以通过传递额外的数据来控制演示文稿,然后您可以在模板中使用 -

<下面是一个例子。 -



http:// jsbin .com / yateka / 1 /编辑?html,输出



列表以及您希望如何提供它,然后使用该内容创建模板。

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

解决方案

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.

这篇关于将数据绑定到Polymer中的内容元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆