Vue.js 模态对话框不显示值

Vue.js Modal Dialog doesn't show value

我有一个模式对话框,应该会自动填充值。 它看起来像这样:

正如您在控制台中看到的那样,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>

行中有错误 this.commentData.selectedCategory = listCategory;

替换为 this.selectedCategory = listCategory;

你这里有问题:

  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;