Polymer:通过标记将数组传递给property

时间:2016-10-07 10:29:20

标签: javascript arrays polymer

我创建了一个具有数组属性' icon-buttons'的元素。我可以使用javascript传递数组但是当我在标记中传递它时,它不起作用。

属性:



iconButtons: {
  type: Array,//tried Object as well
    value: function() { return []; }
}




用法:



<my-card heading="Demo 2" icon-buttons='[
                    {"name" : "edit", "icon" : "icons:create", "click" : "toggleMode();", "disabled" : false},
                    {"name" : "close", "icon" : "icons:clear", "click" : "alert(''close'');", "disabled" : false},
                    {"name" : "maximize", "icon" : "icons:fullscreen", "click" : "alert(''maximize'');", "disabled" : false},
                    {"name" : "more", "icon" : "icons:more-vert", "click" : "alert(''more'');", "disabled" : true}
                  ]'>
            <div class="card-content">
              <list mode="edit"></list>
            </div>
            <div class="card-actions">
              <paper-button>Hello</paper-button>
              <paper-button>Bye</paper-button>
            </div>
          </my-card>
&#13;
&#13;
&#13;

我已经为另一个元素传递了类似的JSON对象。但是这个带Array的功能不起作用。 这有什么问题?

1 个答案:

答案 0 :(得分:0)

a1626是正确的,在您的提醒中使用\"代替''

... "click": "alert(\"close\");", ...