【发布时间】:2017-12-03 08:51:17
【问题描述】:
enter image description herebelow 代码 sn-p 用于从 Iron ajax 调用中获取 json 数据。我能够在 mapResponse 中获取 json 对象值。 我想获取 json 数据中的结果数组的值,并希望将此结果对象值作为输入属性传递到另一个聚合物组件中
从 Iron ajax 加载数据的代码
<iron-ajax
id="originalData"
auto
url="{{originalDataURL}}"
handle-as="json"
last-response="{{originalData}}" on-response="mapResponse">
</iron-ajax>
Json file
{
"tags": [
{
"name": "test",
"results": [
{
"groups": [
{
"name": "type",
"type": "number"
}
],
"values": [
[
946890000000,
99.93584833,
3
],
[
946846800000,
99.94809842,
3
],
[
946803600000,
99.96034846,
3
],
[
946760400000,
99.97259848,
3
],
[
946717200000,
99.98484848,
3
]
],
"attributes": {}
}
],
"stats": {
"rawCount": 5
}
}
]
}
<script>
Polymer({
is: 'test-view',
properties: {
results: {
type: Array
},
mapResponse: function (data) {
var dummy = data.detail.response;
console.log("resposne is ",dummy);
results = dummy.results;
console.log("array is ",results);
},
我尝试在控制台日志中获取上述结果数组对象值,但未定义。在这里,我能够获取 dummy 的值,其中我正在获取完整的 json 对象(标签)我只想从此(标签)对象获取结果数组对象。
谁能建议我如何只获得结果数组值? 提前致谢。
【问题讨论】:
-
假人的类型是什么,如果是字符串,则执行
dummy=JSON.parse(dummy)。下面var dummy = data.detail.response; -
dummy 是数组,我们以这种方式在控制台上获取数据作为附加的虚拟响应屏幕截图。我想要这个虚拟对象的结果数组对象。
-
你能登录假人吗?什么是
typeof(data) -
是的,我可以在记录 console.log("resposne is ",dummy); --- -- 响应是 {tags: Array(1)}
-
我附上了屏幕截图链接,以获得更多我在虚拟i.stack.imgur.com/uWSit.png中得到的内容@
标签: javascript ajax polymer-1.0