2017-04-16 1 views
1

이 문자열 변수는 js로 정의됩니다. 내가 ES6이 점을 변환 할 때 내가 +를 사용하여 다음 행으로 그것을 깰 줄에 125 개 문자를 초과 들어Es6 서식 오류?

bodycontent = 'Hello ' + studentName + '%0D%0AThe course ' + courseName 
       + ' is using the TEAMMATES System to collect feedback.%0D%' 
       + '0ATo \'join\' the course, please go to this Web address: ' 
       + encodeURIComponent(uri) + '%0D%0A*If prompted to log in, ' 
       + 'use your Googleaccount to log in. If you do not ' 
       + 'have a Google account, please create one from the ' 
       + encodeURIComponent('https://accounts.google.com/NewAccount') 
       + '%0D%0A*The above link is unique to you. Please do not ' 
       + 'share it with your classmates.%0D%0ANote that If you ' 
       + 'wish to access TEAMMATES without using your Googleaccount, ' 
       + 'you do not need to \'join\' the course as instructed ' 
       + 'above. You will still be able to submit/view feedback ' 
       + 'by following the instructions sent to you by TEAMMATES at the ' 
       + 'appropriate times. However, we recommend joining the courseusing ' 
       + 'your Google account, because it gives you more convenient ' 
       + 'access to all your feedback stored in TEAMMATES.%0D%0A%0D%0A' 
       + 'If you encounter any problems when using the system, you can ' 
       + 'email TEAMMATES support team at [email protected]%0D%0A%0D%0A' 
       + 'Regards,%0D%0ATEAMMATES Team.'; 

이제 문제입니다.

 bodycontent = `Hello ${studentName}%0D%0AThe following feedback session is ${status}%0D%0A` 
        + `Course: [${Id}]${courseName}%0D%0AFeedback Session Name: ${Id}%0D%0A` 
        + `The link of the feedback for the above session, please go to this Web ` 
        + `address: ${encodeURIComponent(uri)}%0D%0A*The above link is unique to you.` 
        + `Please do not share it with others.%0D%0A%0D%0AIf you encounter any problems` 
        + `when using the system, you can email TEAMMATES support team at [email protected]%0D%0A%0D%0ARegards,%0D%0ATEAMMATES Team.`; 

이렇게하면 변수를 포함하지 않는 줄마다 "문자열에 작은 따옴표를 사용해야합니다"라는 오류 메시지가 표시됩니다.

또한

bodycontent = `Hello ${studentName}%0D%0AThe following feedback session is ${status}%0D%0A 
        Course: [${Id}]${courseName}%0D%0AFeedback Session Name: ${Id}%0D%0A 
        The link of the feedback for the above session, please go to this Web 
        address: ${encodeURIComponent(uri)}%0D%0A*The above link is unique to you.` 
        ...... 

그러나 문제는 내가 얻고있다 "\ n을"내가 원하지 않는 내 문자열에서 개행의 추가는 친절하게 휴식을 나에게 효율적인 방법을 말해이 같은 라인을 깰 수 내 문자열에 \ n 추가하지 않고 행.

답변

0

접두사가 붙은 템플릿 리터럴에 common-tags 패키지를 사용하십시오. npm을 사용하지 않으면 구현을 복사 할 수도 있습니다.

oneLine 태그는 모든 줄 바꿈과 들여 쓰기를 하나의 공백으로 변경합니다. 마지막 공백을 제거하려면 oneLineTrim을 사용하십시오.

1

템플릿 리터럴에 포함 된 공백이 포함되어 줄 바꿈을받는 이유입니다. 템플릿 리터럴의 예상되는 동작입니다.

$('div.post').html("<h3>Some title here</h3> " + 
    "<p>Lorem ipsum doloramet, onsectetur adipiscing elit " + 
    "sed do eiusmod tempor incididunt ut labore..."); 

이된다 :

$('div.post').html(` 
    <h3>Some title here</h3> 
    <p>Lorem ipsum doloramet, onsectetur adipiscing elit 
    sed do eiusmod tempor incididunt ut labore... 
`); 

그것은 당신처럼 보인다 템플릿 리터럴이 기능 예는, 해결을위한 필요없이 여러 줄에 걸쳐 문자열을 만들 수 있습니다 String 길이의 결과로 여러 줄로 만 실행하려는 경우 이 문제는 주관 텍스트 편집 기본 설정에 관한 것입니다.

당신이 텍스트 랩 당신의 IDE에서를 사용하여 시도 유무 :

는 Soution 제안?