问题
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": " "
}],
}
回答1:
if you could share the value of the array that would be awesome.
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
来源:https://stackoverflow.com/questions/59082887/freshdesk-sample-payload-array-of-objects