首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从dart代码嵌套web组件

从dart代码嵌套web组件
EN

Stack Overflow用户
提问于 2013-07-03 17:09:16
回答 1查看 447关注 0票数 2

我有多个嵌套的web组件来表示网格。我需要用飞镖代码来写这些。我有一个函数来创建web组件,这是由dart文档推荐的:

代码语言:javascript
复制
void addWebComponent(WebComponent component,String tagName,WebComponent parent) { 
    component.host = (new Element.html("<${tagName}></${tagName}>"));        
    var lifecycleCaller = new ComponentItem(component)
    ..create();
    parent.append(component.host);
    lifecycleCaller.insert();
    return;
}

每个web组件都包含如下模板:

代码语言:javascript
复制
  <template>
      <div class="grid">
         <div class="large-12 columns" >                    
            <content></content>
         </div>
       </div>          
  </template>

我的假设是,调用parent.append(component.host);会将注入的web组件html添加到内容元素中。没有。这正是我所期望的结果:

代码语言:javascript
复制
<x-grid>
      <div class="grid">
         <div class="large-12 columns">
             <x-row> 
                  <div class="row">...</div>           
             </x-row>
         </div>
       </div>          
</x-grid>

我得到的是:

代码语言:javascript
复制
 <x-grid>
      <div class="grid">
         <div class="large-12 columns"> 
                 **[Content should be here!]**               
         </div>
       </div>    
         **[ CONTENT ENDS UP HERE]**
         <x-row> 
                  <div class="row">...</div>           
             </x-row>

</x-grid>

我的猜测是,从dart代码中,您不能通过parent.append(component.host)添加到web组件的内容中。是否还需要其他一些功能或步骤来完成这项工作?我要死了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-04 14:37:46

试试这个:

在父母中添加:

代码语言:javascript
复制
List<WebComponent> items = toObservable([]);

更改:

代码语言:javascript
复制
parent.append(component.host);

至:

代码语言:javascript
复制
parent.items.add(component);

然后修改HTML如下:

代码语言:javascript
复制
<template>
  <div class="grid">
     <div class="large-12 columns" template iterate="item in items">                    
        {{ new SafeHtml.unsafe(item.host.innerHtml) }}
     </div>
  </div>          
</template>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17454165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档