如果调用简单字符串,我有这段代码可以工作
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对象数组
发布评论