내 코드과 같이 배치 :React를 사용하여 여러 파일에서 변수를 호출 하시겠습니까?
가 IndexDB가 Dexie.js 래퍼 사용 datastored
변수를 통해
var React = require('react');
var ReactDOM = require('react-dom');
var Console = require('./console.jsx');
var Dashboard = require('./dashboard.jsx');
var datastored = new Dexie('Notes');
datastored.version(1).stores({entries:'++id, title, entry' });
datastored.open().catch(function(err){alert("Could not open database:"+err)});
이 main.jsx
부츠가 내 데이터베이스을 main.jsx. 이제 다른 파일 (예 : console.jsx
또는 dashboard.jsx
)의 변수 datastored
을 호출하고 싶습니다.
내 특별한 경우에 <Addnote/>
이 <Dashboard/>
입니다. 안에 <Addnote/>
나는이 기능이있다. sendthru
이 시작되면
addnote.jsx는
sendthru:function(){
var newInput = {
title: this.inputTitle.value,
entry: this.inputEntry.value
};
datastored.entries.add(newInput).then(()=>this.runcheck());
this.inputTitle.value = '';
this.inputEntry.value = '';
},
그러나, 내 콘솔 오류는 datastored is not defined
을 말한다. 그래서 내 전체 앱이 datastored
변수를 호출 할 수있게 할 수 있을지 궁금하다.
'main.jsx'에서'var datastored = require ('./ storage.js')'처럼 보일까요? 그리고 storage.js에서'module.exports = new Dexie ('Notes');와 같이 보일 것입니다. –
물론 더 많은 데이터가 필요하다면 그걸 시작하고 바꿀 수 있습니다. – John