Vue. js Модальное диалоговое окно не показывает значение - PullRequest
0 голосов
/ 10 апреля 2020

У меня есть модальное диалоговое окно, которое должно заполняться автоматически значениями. Выглядит это так:

enter image description here

Как видно на консоли, listCategory имеет значение Social (Comment), но оно не отображается в модальном диалоге, и я не знаю почему.

Значение имеет только то, что я напишу так:

return {
  commentData: {
     comment: "",
     customDate: ""
  },
  selectedCategory: "Social (Comment)",
  lang: {
      default: "en"
  }
};

Я не слишком знаком с Vue. js именно поэтому я хочу знать, как можно назначить listCategory на selectedCategory.

Это не работает:

selectedCategory: listCategory,

Также не работает:

selectedCategory: this.listCategory,

Вот код:

export default {
        props: ["text"],
        components: { DatePicker },
        data: function() {
            var listCategory;
            var listComment;
            var listDate;

            let siteUrl = 'https://thesite.sharepoint.com/sites/Playercard/';
            let clientContext = new SP.ClientContext(siteUrl);
            let oList = clientContext.get_web().get_lists().getByTitle('Comment');
            let camlQuery = new SP.CamlQuery();

            camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'ID\'/>' +
                '<Value Type=\'Number\'>100</Value></Eq></Where></Query></View>');
            var collListItem = oList.getItems(camlQuery);
            clientContext.load(collListItem);
            console.log("clientContext loaded!");

            // First we much execute the query to retrieve the items
            clientContext.executeQueryAsync(()=> {
                    // Now colListItem is a collection, we must iterate through it
                    var listItemEnumerator = collListItem.getEnumerator();

                    while (listItemEnumerator.moveNext()) {
                        var oListItem = listItemEnumerator.get_current();
                        listDate = oListItem.get_item('Date');
                        listCategory = oListItem.get_item('Category');
                        listComment = oListItem.get_item('Comment');
                    }

                    console.log("listDate: " + listDate);
                    console.log("listCategory " + listCategory);
                    console.log("listComment: " + listComment);
                    this.commentData.customDate = listDate;
                    this.commentData.selectedCategory = listCategory;
                    this.commentData.comment = listComment;

                    clientContext.executeQueryAsync(
                        () => console.log('Item(s) edited')),
                        () => console.log('Failed to edit item(s)');
                },
                ()=>console.log('Failed to retrieve items'));

            return {
                commentData: {
                    comment: "",
                    customDate: ""
                },
                selectedCategory: "",
                lang: {
                    default: "en"
                }
            };
        },

Вот соответствующая часть шаблона:

<div class="row">
    <div class="d-inline col-lg-4 col-md-4 col-sm-4" padding="0px">
        Category
        <font color="red">*</font>
    </div>
    <div class="d-inline col-lg-8 col-md-8 col-sm-8" padding="0px">
        <select v-model="selectedCategory">
            <option>Social (Comment)</option>
            <option>Sport (Comment)</option>
            <option>School (Comment)</option>
            <option>Others (Comment)</option>
        </select>
    </div>
</div>

Ответы [ 2 ]

1 голос
/ 10 апреля 2020

У вас есть проблема здесь:

  console.log("listCategory " + listCategory);
  console.log("listComment: " + listComment);
  this.commentData.customDate = listDate;
  this.commentData.selectedCategory = listCategory;        -----------> Your commentData dict does not have selectCategory as a key
  this.commentData.comment = listComment;

Измените ее на:

      console.log("listCategory " + listCategory);
      console.log("listComment: " + listComment);
      this.commentData.customDate = listDate;
      this.selectedCategory = listCategory;      
      this.commentData.comment = listComment;
1 голос
/ 10 апреля 2020

ошибка в строке this.commentData.selectedCategory = listCategory;

замените ее на this.selectedCategory = listCategory;

...