您好我在尝试使用handontables,当我对数据进行硬编码时工作正常,但是当我尝试使用模式时,我需要它才能使其工作。我一直关注这篇旧帖Meteor Handsontable example。除了改变
我做了一切// Remove "var" from Handsontable declaration to add to global scope
var Handsontable = function (rootElement, userSettings) {
...
// New code
Handsontable = function (rootElement, userSettings) {
...
我似乎无法在任何地方找到它。
我拥有的是什么。
products.js
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Product = new Mongo.Collection('product');
ProducSchema = new SimpleSchema({
name: {
type: String,
},
m1: {
type: Number,
defaultValue: 0
},
m2: {
type: Number,
defaultValue: 0
},
m3: {
type: Number,
defaultValue: 0
},
m4: {
type: Number,
defaultValue: 0
},
});
Product.allow({
insert: function (userId, doc) {
// the user must be logged in, and the document must be owned by the user
return !!userId;
},
update: function (userId, doc) {
// can only change your own documents
return !!userId;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
},
fetch: ['owner']
});
Product.attachSchema( ProducSchema );
productSingle.js
import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import { Product } from '../../../../../api/lists/Products.js';
import './ProductSingle.html';
if (Meteor.isClient) {
Template.ProductSingle.onCreated(function() {
var self = this;
self.autorun(() => {
self.subscribe('product');
})
});
Template.ProductSingle.rendered = function() {
var myData = []; // Need this to create instance
var container = document.getElementById("productSingle");
var hot = new Handsontable(container, { // Create Handsontable instance
data: myData,
startRows: 5,
startCols: 5,
colHeaders: true,
rowHeaders: true,
minSpareRows: 1,
contextMenu: true,
afterChange: function(change, source) { // "change" is an array of arrays.
if (source !== "loadData") { // Don't need to run this when data is loaded
for (i = 0; i < change.length; i++) { // For each change, get the change info and update the record
var rowNum = change[i][0]; // Which row it appears on Handsontable
var row = myData[rowNum]; // Now we have the whole row of data, including _id
var key = change[i][1]; // Handsontable docs calls this "prop"
var oldVal = change[i][2];
var newVal = change[i][3];
var setModifier = {
$set: {}
}; // Need to build $set object
setModifier.$set[key] = newVal; // So that we can assign 'key' dynamically using bracket notation of JavaScript object
MyCollection.update(row._id, setModifier);
}
}
}
});
Tracker.autorun(function() { // Tracker function for reactivity
myData = Product.find().fetch(); // Tie in our data
hot.loadData(myData);
console.log(myData);
});
};
}
这并不像第一行那样显示任何表格。
如果我点击这个就会收到错误:
awsp_handsontable.js?hash=45775ff…:25594 Uncaught Error: column 0 does not exist(…)
如果有人能帮我解决这个问题会很棒,这对我来说是一个很大的障碍