我正在尝试将Kendo UI上的数据与Vuex Getters中的数据绑定。
我试过以下方法,但没有运气。无论我在Vuex还是Kendo上错过什么,请帮忙。
Kendo扩展:
<kendo-grid :data-source="kendoDataSource">
</kendo-grid>
组件:
computed: {
customers() {
return this.$store.getters.customers;
}
},
data() {
return {
kendoDataSource: {
schema: {
data: function(response) {
return response;
},
model: {
id: "CustomerID",
fields: {
CompanyName: { type: "string" },
}
}
},
transport: {
read: function(options) {
options.success(this.customers);
}
}
}
};
我正在出错。
TypeError: Cannot read property 'length' of undefined
当我尝试调试
this.customers
在Kendo的运输过程中
这个.客户
始终为空。
数据格式如下:
[
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste"
},
{
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados"
}
]
商店.js
export default {
state: {
customers: JSON.parse(JSON.stringify(customers))
},
getters: {
customers(state) {
return state.customers;
}
}
};
当我试图将数据直接绑定到
options.success(this.customers);
如下面所示,成功地用数据填充网格。但是当我试图用
getters
有错误。
类型错误:无法读取未定义的属性“length”
options.success([
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
},
{
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados",
}
]);