我一直在阅读nodebeginner 而且我遇到了以下两段代码.
第一个:
var result = database.query("SELECT * FROM hugetable");
console.log("Hello World");
Run Code Online (Sandbox Code Playgroud)
第二个:
database.query("SELECT * FROM hugetable", function(rows) {
var result = rows;
});
console.log("Hello World");
Run Code Online (Sandbox Code Playgroud)
我得到了他们应该做的事情,他们查询数据库以检索查询的答案.然后console.log('Hello world').
第一个应该是同步代码.第二个是异步代码.
两件作品之间的区别对我来说非常模糊.输出会是什么?
谷歌搜索异步编程也没有帮助我.
我试着打开文件
window.open("file:///D:/Hello.txt");
Run Code Online (Sandbox Code Playgroud)
浏览器不允许以这种方式打开本地文件,可能是出于安全原因.我想在客户端使用该文件的数据.如何在Javascript中读取本地文件?
我是react.js的新手我实现了一个组件,我从服务器获取数据并使用它,如,
CallEnterprise:function(TenantId){
fetchData('http://xxx.xxx.xx.xx:8090/Enterprises?TenantId='+TenantId+' &format=json').then(function(enterprises)
{
EnterprisePerspectiveActions.getEnterprise(enterprises);
}).catch(function()
{
alert("There was some issue in API Call please contact Admin");
//ComponentAppDispatcher.handleViewAction({
// actionType: MetaItemConstants.RECEIVE_ERROR,
// error: 'There was a problem getting the enterprises'
//});
});
},
Run Code Online (Sandbox Code Playgroud)
我想将Url存储在配置文件中,所以当我在测试服务器或生产上部署它时,我只需更改配置文件中的url而不是js文件,但我不知道如何在react.js中使用配置文件
任何人都可以指导我如何实现这一目标?
我的代码在构造之后的某处:
var getMenu = function () {
return window.fetch("portal/content/json/menu.json").then(function (data) {
return data.json();
});
};
Run Code Online (Sandbox Code Playgroud)
我尝试过webpack.config.js这个:
module: {
loaders: [
...
{
test: /\.json$/,
exclude: /node_modules/,
use: [
'file-loader?name=[name].[ext]&outputPath=portal/content/json'
]
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
项目结构:
dist
content
json
menu.json <- this is missing
src
content
json
menu.json <- source file
Run Code Online (Sandbox Code Playgroud)
题:
webpack如何复制src/content/json/menu.json到dist/content/json/menu.json?
我正在尝试从react组件中的json文件加载数据.我正在我的app.js中尝试这个解决方案.
var data = require('json!../json/acordes.json');
Run Code Online (Sandbox Code Playgroud)
终端中"无法解析模块JSON错误".
我在app.js文件中执行此操作.我的文件夹结构如下:
/src
/js
app.js
/css
/json
acordes.json
Run Code Online (Sandbox Code Playgroud)
我的其余代码如下所示:
https://gist.github.com/dabit3/651f2dae058ff99810eb771c2817d622
javascript ×4
json ×2
reactjs ×2
webpack ×2
angularjs ×1
asynchronous ×1
flux ×1
local-files ×1
node.js ×1
react-native ×1
synchronous ×1