gpt4 book ai didi

JavaScript this.todoList.filter 不是函数

转载 作者:行者123 更新时间:2023-12-01 15:53:54 25 4
gpt4 key购买 nike

我想在 Vue.js 中创建一个 ToDo 列表,但项目没有显示出来。 (当我使用 localStorage 存储项目时它可以工作,但是当我在 SharePoint 上使用列表时它不会)

enter image description here

问题很可能是这部分(因为我改编了代码):

computed: {
pending: function () {
console.log("pending");
if (!this.todoList) {
return [];
}
return this.todoList.filter((item) => !item.done);
}

我使用 getToDos 方法获取 ToDo 列表项:

 methods: {
getTodos() {
let siteUrl = 'https://thesite.sharepoint.com/sites/Playercard/';
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('PhysicalGoals');
var camlQuery = new SP.CamlQuery();
var playerID = this.$store.state.selectedPlayer.ID;
console.log("playerID getTodos: " + playerID);
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'playerID\'/>' +
'<Value Type=\'Text\'>'+playerID+'</Value></Eq></Where></Query></View>');

collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);

clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceededNew),
Function.createDelegate(this, this.onQueryFailedNew)
);
},
onQuerySucceededNew(){
console.log("onQuerySucceededNew!");
var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
this.todoList = oListItem.get_item('Title');
console.log("this.todoList: " + this.todoList);
}
console.log("this.todoList: " + this.todoList);
console.log("this.todoList.toString(): " + this.todoList.toString());
console.log("this.todoList.length): " + this.todoList.length);

}

我认为问题是 item,但我不知道我必须如何调整代码。它是一个包含 HTML、CSS 和 JS 的单一文件组件。这是full component .

有人知道如何解决这个问题吗?

最佳答案

问题出在 onQuerySucceededNew() 函数中。您必须将项目插入数组。

示例解决方案:

onQuerySucceededNew(){
var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
this.todoList.push(oListItem.get_item('Title'));
}
}

编辑

并确保将 this.todoList 定义为组件中的数组。

data() {
return {
todoList: [],
}
},

关于JavaScript this.todoList.filter 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61027624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com