gpt4 book ai didi

javascript - 如何将数组传递给 polymer 中的内部html

转载 作者:行者123 更新时间:2023-11-30 15:56:10 25 4
gpt4 key购买 nike

我对 polymer 完全陌生。我想画一个图...

我有一个 html,其中包含像这样的属性...用于 dom 模块

<some-container content_content-type = 'Real Estate' content_content-num = 'PF HP 001078' key-type = 'vpn_key' graphmax = 620000 graphmin = 540000 currency = 'USD' oldvalue-amount = 550000 new-value-amount = 2300 new-valuecolor = 'green-text' new-valueplusminus = '+' morelink = '#' containerlink = 'education.html' graphdata = [['Tue', 600000],['Wed', 590000],['Thu', 580000],['Fri', 575000],['Sat', 590000],['Sun', 575000],['Mon', 550000],['Tue', null]]></some-container>

现在我想发送这个数组 graphdata 作为参数……就像我发送其他的一样……content_content-type、content_content-num 等。

<dom-module id="some-container">
<template>
….HTML…
</template>
<script>
Polymer({
is: 'some-container',
properties: {
content_contentType: {
type: String,
notify: true
},
content_contentNum: {
type: String,
notify: true
},
….
graphdata: {
type: Array,
value: []
},
….
};
attached: function() {
this._drawgraph(this.graphmax,this.graphmin,this.graphid,this.graphdata); // _drawgraph is some other function where functionality/calculations are…
//If I debug I see this.graphmax, this.graphmin has data… but not this.graphdata
},

但我看到 this.graphdata 没有获取数据。它是未定义的。

关于如何从外部 HTML 传递数组的任何建议

最佳答案

要将带引号的 [JSON|Array] 直接传递给 HTML 中的元素属性,您必须反转引号。属性值必须用单引号括起来,实际字符串必须使用双引号。否则 Polymer 无法解析它,因为单引号不是正确的 JSON 语法。因此你的代码应该是

<some-container graphdata='[["Tue", 600000],["Wed", 590000],["Thu", 580000],["Fri", 575000],["Sat", 590000],["Sun", 575000],["Mon", 550000],["Tue", null]]'></some-container>

关于javascript - 如何将数组传递给 polymer 中的内部html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38494784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com