我有一个模式对话框,应该自动填充值。
看起来像这样:
正如您在控制台中看到的那样,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;
关于javascript - Vue.js模式对话框不显示值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61141294/