【问题标题】:Vue.js Modal Dialog doesn't show valueVue.js 模态对话框不显示价值
【发布时间】:2020-04-10 13:27:15
【问题描述】:

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

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

【问题讨论】:

  • 您是否使用 v-select 来选择类别?
  • @AbhishekKulkarni 我使用 v-model。编辑了帖子

标签: javascript vue.js modal-dialog variable-assignment assign


【解决方案1】:

错误在行 this.commentData.selectedCategory = listCategory;

替换为 this.selectedCategory = listCategory;

【讨论】:

    【解决方案2】:

    这里有问题:

      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;
    

    【讨论】:

      猜你喜欢
      • 2016-02-25
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 2021-10-18
      • 2020-03-02
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      相关资源
      最近更新 更多