您好我正在尝试从集合中检索一些数据。我发现这样的集合。
var myData = Product.find({ _id: id}).fetch();
OR
var myData = Product.find({ _id: id});
返回
[object Object]
如果我尝试访问数据,我会得到未定义的
myData.data._id
myData._id
myData.selling.t1
全部未定义。任何想法
类
import {
Template
} from 'meteor/templating';
import {
Meteor
} from 'meteor/meteor';
import {
Product
} from '../../../../../api/lists/Products.js';
import './ProductSingle.html';
if (Meteor.isClient) {
var id;
Template.ProductSingle.onCreated(function() {
var self = this;
self.autorun(() => {
self.subscribe('product');
});
id = this.data._id;
});
Template.ProductSingle.onRendered(function() {
var myData = Product.find({ _id: id}); // Need this to create instance
console.log("this data" + myData.data._id);
var container = document.getElementById(this.data.name + "Container");
var hot = new Handsontable(container, { // Create Handsontable instance
data: [[]],
startRows: 2,
startCols: 12,
minCols: 12,
minRows: 2,
colHeaders: true,
rowHeader: ['Selling Price', 'Purchase Price'],
minSpareRows: 1,
contextMenu: true,
cells: function(row, col, prop, value) {
var cellProperties = {
type: 'numeric',
format: '0.00'
};
cellProperties.renderer = rowRenderer;
return cellProperties;
}
// 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);
// }
// }
// }
});
function rowRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
var rowId;
switch(row) {
case 0:
//rowId = myData.sellingPrice.M;
//console.log(myData)
break;
case 1:
rowId = myData.purchasePrice;
break;
}
if (!value || value === '' || value == null) {
console.log(rowId+col)
//td.innerHTML = rowId+col;
}
}
// Tracker.autorun(function() { // Tracker function for reactivity
// myData = Product.findOne({ _id: id}); // Tie in our data
// hot.loadData(myData);
// console.log(myData);
// });
});
}
我现在很安静,为什么我无法访问对象数据。如果我可以在模板端访问它