2016-10-06 5 views
3

データバインディングを持つ信頼できるhtmlファイルをWebコンポーネントに含める.htmlファイルをインクルードする方法は複数試みたが、データバインディングは機能しない。信頼できない情報源からのXSS攻撃の脆弱性があるため、ポリマーはhtmlをスタンプしませんが、信頼できる情報源があります。データバインディングを含むポリマーにhtmlを注入する

は、私はすでに12の意識だとiron-ajaxinjectBoundHTML機能inner-h-t-m-lでも、ジューシー-HTMLを試してみました。

自分でバインドする以外の方法はありますか?

含めるファイルには入力フィールドが含まれており、定義済みのフォームです。

答えて

2

Templatizerは、<template>を手動で作成して内容を設定することで使用できます。重要な部分はあなただけ私はあなたのスニペットを試してみたし、それが動作innerHTML

Polymer({ 
 
    is: 'my-elem', 
 
    behaviors: [ Polymer.Templatizer ], 
 
    ready: function() { 
 

 
    var template = document.createElement('template'); 
 
    
 
    // you must prepare the template content first (with bindings) 
 
    var templateContent = document.createElement('div'); 
 
    templateContent.innerHTML = 'First: <span style="color: red">[[person.first]]</span> <br> Last: <span style="color: green">[[person.last]]</span>'; 
 
    
 
    // and cannot simply set template's innerHTML 
 
    template.content.appendChild(templateContent); 
 
    
 
    // this will process your bindings 
 
    this.templatize(template);   
 
    var person = { 
 
     first: 'Tomasz', 
 
     last: 'Pluskiewicz' 
 
    }; 
 
    var itemNode = this.stamp({ person: person }); 
 
    
 
    Polymer.dom(this.root).appendChild(itemNode.root); 
 
    } 
 
});
<!DOCTYPE html> 
 
<html> 
 

 
    <head> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.7.19/webcomponents.min.js"></script> 
 
    <link rel="import" href="https://raw.githubusercontent.com/Polymer/polymer/master/polymer.html" /> 
 
    </head> 
 

 
    <body> 
 
    <my-elem> 
 
    </my-elem> 
 
     
 
    <dom-module id="my-elem"> 
 
     <template> 
 
     </template> 
 
    </dom-module> 
 
    </body> 
 

 
</html>

+0

を設定することができないということです。テンプレート内のデータバインディングが機能しています。複雑なオブジェクトをスタンプすることは可能ですか?また、外部要素とのデータバインディングもありません。スタンピングは一方向のみです。 var itemNode = this.stamp({i:this.data}); data = { name = "Alex" } – aphex

+1

はい、任意のオブジェクトをバインドできます(更新を参照)。 2ウェイバインディングは可能ですがトリッキーです。このビンを参照してください:http://jsbin.com/kipato/edit?html,js,output –

+0

例をありがとうございます。データバインディングは今動作しています:)イベントを渡す方法を知っていますか?フィールドはイベントを起動していますが、外部コンテキストはイベントを表示しません。 – aphex

関連する問題