【发布时间】:2020-07-16 13:14:50
【问题描述】:
我想在 Vue.js 中创建一个 ToDo 列表,但项目没有显示出来。 (当我使用 localStorage 存储项目时它可以工作,但当我在 SharePoint 上使用列表时它不会)
问题很可能是这部分(因为我改编了代码):
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。
有人知道如何解决这个问题吗?
【问题讨论】:
-
我确定问题不在
pending计算属性中。问题是this.todoList不是数组。 -
在控制台日志中可以看到,是一个字符串。
标签: javascript arrays vue.js sharepoint vuejs2