Freshdesk Sample Payload对象数组

编程入门 行业动态 更新时间:2024-10-26 06:26:36
本文介绍了Freshdesk Sample Payload对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果调用简单字符串,我有这段代码可以工作

I had this code that works if simple string is called

$(document).ready( function() { app.initialized() .then(function(_client) { var client = _client; client.events.on('app.activated', function() { client.data.get('ticket') .then(function(data) { $('#issue_title').text("Issue:" + data.ticket.description); }) .catch(function(e) { console.log('Exception - ', e); }); }); }); });

但是当我将其更改为数组对象时,它不起作用

But when I change it to array object it doesnt work

$(document).ready( function() { app.initialized() .then(function(_client) { var client = _client; client.events.on('app.activated', function() { client.data.get('ticket') .then(function(data) { $('#issue_title').text("Issue:" + data.ticket.attachments['name']); }) .catch(function(e) { console.log('Exception - ', e); }); }); }); });

我正在使用此票证的附件有效载荷

Im using this ticket ATTACHMENTS payload

Sample Payload { "ticket": { "attachments": [], "cc_emails": [], "company_id": 1, "created_at": "2017-04-12T06:05:56.000Z", "custom_fields": [{ "custom_number": null, "custom_line1": " " }], }

推荐答案

是否可以共享很棒的数组值.

if you could share the value of the array that would be awesome.

目前,您试图将Array当作对象来进行导航,Array是基于索引的,并且没有键:)

For now you are trying to navigate an Array as if it were an object, Array's are index based and don't have keys :)

如果您可以这样更新有效载荷

If you can update the payload as such

{ "ticket": { "attachments": { name: "", }, "cc_emails": [], "company_id": 1, "created_at": "2017-04-12T06:05:56.000Z", "custom_fields": [{ "custom_number": null, "custom_line1": " " }], }

否则,我不确定您如何期望数组返回您的值.

Otherwise i'm not sure how you are anticipating the array to return your value.

如果它是具有[键,值,键,值]结构的数组,则可以

If it is an array with the structure [key, value, key, value] you can go

data.ticket.attachments[data.ticket.attachments.indexOf('name') + 1]

最后,如果它是对象数组,则可以

Finally if it's an array of objects you can go

data.ticket.attachments.find(attachment => attachment.key === 'name').YourKey

更多推荐

Freshdesk Sample Payload对象数组

本文发布于:2023-11-27 01:45:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636062.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   对象   Freshdesk   Sample   Payload

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!