работа с FirestoreDocument

Отправьте электронное письмо с помощью JavaScript или jQuery

var ConvertedFileStream;
var g_recipient;
var g_subject;
var g_body;
var g_attachmentname;


function SendMailItem(p_recipient, p_subject, p_body, p_file, p_attachmentname, progressSymbol) {

    // Email address of the recipient 
    g_recipient = p_recipient;

   // Subject line of an email
    g_subject = p_subject;

   // Body description of an email
    g_body = p_body;

    // attachments of an email
    g_attachmentname = p_attachmentname;

    SendC360Email(g_recipient, g_subject, g_body, g_attachmentname);

}

function SendC360Email(g_recipient, g_subject, g_body, g_attachmentname) {
    var flag = confirm('Would you like continue with email');
    if (flag == true) {

        try {
            //p_file = g_attachmentname;
            //var FileExtension = p_file.substring(p_file.lastIndexOf(".") + 1);
           // FileExtension = FileExtension.toUpperCase();
            //alert(FileExtension);
            SendMailHere = true;

            //if (FileExtension != "PDF") {

            //    if (confirm('Convert to PDF?')) {
            //        SendMailHere = false;                    
            //    }

            //}
            if (SendMailHere) {
                var objO = new ActiveXObject('Outlook.Application');

                var objNS = objO.GetNameSpace('MAPI');

                var mItm = objO.CreateItem(0);

                if (g_recipient.length > 0) {
                    mItm.To = g_recipient;
                }

                mItm.Subject = g_subject;

                // if there is only one attachment                 
                // p_file = g_attachmentname;
                // mAts.add(p_file, 1, g_body.length + 1, g_attachmentname);

                // If there are multiple attachment files
                //Split the  files names
                var arrFileName = g_attachmentname.split(";");
                 // alert(g_attachmentname);
                //alert(arrFileName.length);
                var mAts = mItm.Attachments;

                for (var i = 0; i < arrFileName.length; i++)
                {
                    //alert(arrFileName[i]);
                    p_file = arrFileName[i];
                    if (p_file.length > 0)
                    {                     
                        //mAts.add(p_file, 1, g_body.length + 1, g_attachmentname);
                        mAts.add(p_file, i, g_body.length + 1, p_file);

                    }
                }

                mItm.Display();

                mItm.Body = g_body;

                mItm.GetInspector.WindowState = 2;

            }
            //hideProgressDiv();

        } catch (e) {
            //debugger;
            //hideProgressDiv();
            alert('Unable to send email.  Please check the following: \n' +
                    '1. Microsoft Outlook is installed.\n' +
                    '2. In IE the SharePoint Site is trusted.\n' +
                    '3. In IE the setting for Initialize and Script ActiveX controls not marked as safe is Enabled in the Trusted zone.');
        }
    }
  }
0
задан KENdi 13 July 2018 в 12:41
поделиться

1 ответ

Остальная часть вашего кода выглядит правильно, я думаю, что ваш console.log(this) находится в неправильном месте.

ngOnInit() {
  this.getPost();     <----- your getPost() function is asynchronous
  console.log(this);  <----- meaning this console.log runs before you get data from Firebase
                             so when this runs, posts is still undefined.
                             If you would console.log(this) *AFTER* you get data
                             from Firebase, then you should see the values OK.
}

getPost(){
  const id= this.route.snapshot.paramMap.get('id')
  return this.postService.getPostData(id).subscribe(data=>this.post=data)
                                      ^^^^^^^^^^^
                                        ASYNC portion is right here
}

Чтобы исправить это, переместите консоль.log внутри своей подписки:

ngOnInit() {
  this.getPost();
                    <--- From here
}

getPost(){
  const id= this.route.snapshot.paramMap.get('id')
  return this.postService.getPostData(id).subscribe(data=> {
    this.post=data;
    console.log(this);          <--- To here
  });
}

EDIT - Дополнительное устранение неполадок см. ниже.

getPost(){
  const id= this.route.snapshot.paramMap.get('id')
  console.log('id from route params is: ' + id);   <---- log the *id* too
  return this.postService.getPostData(id).subscribe(data=> {
    this.post=data;
    console.log(data);   <--- log *data* instead
  });
}
0
ответ дан JeremyW 17 August 2018 в 12:54
поделиться
  • 1
    Это не сработало. Пока почта не определена. – jack 13 July 2018 в 12:48
  • 2
    @jack Я отредактировал свое сообщение, чтобы включить некоторые дополнительные шаги по устранению неполадок, можете ли вы включить эти console.logs и сообщить мне результат? – JeremyW 13 July 2018 в 12:52
  • 3
    id из параметров маршрута: данные Gh4WsAxIFxjfqfVj4WzR не определены – jack 13 July 2018 в 13:00
  • 4
    @jack Итак, это означает, что вы даже не получаете данные от Firestore. Глядя на документы Я думаю, что есть проблема с тем, как вы запрашиваете свой документ ... попробуйте использовать этот синтаксис вместо этого и посмотрите, получаете ли вы результат от Firebase db.collection("cities").doc("SF") .onSnapshot({ // Listen for document metadata changes includeMetadataChanges: true }, function(doc) { // ... }); – JeremyW 13 July 2018 в 13:20
Другие вопросы по тегам:

Похожие вопросы: