사과 해. 나는 이것이 다소 초보적인 질문이라고 확신합니다. 그러나 여기에 있습니다! 사전에 힌트를 주셔서 감사합니다 :)
내 앱에 아래 함수가 있으며 이제 앱을 실행하면 "TypeError : parameters.includes is not a function."오류가 발생합니다. 이 오류는 무엇을 의미합니까? if 문에 함수가 필요합니까? 이 조건부를 어떻게 설정해야합니까?
function handleApiAiAction(sender, action, responseText, contexts, parameters, response) {
switch (action) {
case "job-search":
console.log(parameters);
if (parameters.includes("quickreply")) {
console.log("it worked");
} else {
let replies = response.result.fulfillment.messages[0].replies;
let title = response.result.fulfillment.messages[0].title;
sendQuickReply(sender, title, replies);
console.log("it didn't work");
}
break;
default:
//unhandled action, just send back the text
sendTextMessage(sender, responseText);
}
}
console.log ( 'parameters')는 다음을 제공합니다.
{ quickreply: 'quickreply' }
[일부 편집 :)]
{ quickreply: 'quickreply' }
객체 멤버를 포함하지 않는 includes: function() {}
(나 않습니다 Object.prototype
).
하려는 것처럼 보이는 것은 객체에 속성이 포함되어 있는지 확인하는 quickreply
것이므로 다음과 같이해야합니다.
if('quickreply' in parameters) {
// do stuff
}
같은 다른 방법도 사용할 수 있습니다 hasOwnProperty
. 각각 고유의 뉘앙스가 있지만 in
귀하의 경우에는 효과가있는 것처럼 보입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다