草庐IT

function-expression

全部标签

javascript - Express 服务器 - 无法发布/

这个问题在这里已经有了答案:HowtoaccessPOSTformfieldsinExpress(24个答案)关闭7年前。我最近学习了一个关于如何构建Express服务器的简单教程(https://codeforgeek.com/2014/06/express-nodejs-tutorial/)。我正在尝试扩展本教程中的代码,以便我可以响应发布请求。我想通过更新一个json文件来做到这一点(恰好充满了“用户评论”,然后在“/”处重新呈现./server.js:varexpress=require('express');varapp=express();//routingconfigur

javascript - Ant 设计错误 : "Form.create() getFieldDecorator is not a function"

"antd":"^1.11.1","react":"^15.1.0","react-dom":"^15.1.0",错误:未捕获类型错误:getFieldDecorator不是函数Ant设计演示:https://ant.design/components/form/importReact,{Component}from'react';import{Form,Icon,Input,Button}from'antd';constFormItem=Form.Item;constHorizontalLoginForm=Form.create()(React.createClass({handle

javascript - 仅当另一个具有特定值时,Node Js Express Validator 才需要字段

我使用express-validator检查我的帖子字段。我的问题是我只想在其他字段具有特定值时才需要某些字段。例如:ifperson_organisationistrue:person_organisation_namemustberequiredifperson_organisationisfalse:person_first_namemustberequired有什么方法可以将此规则放入验证模式中?? 最佳答案 创建自定义验证:app.use(expressValidator({customValidators:{checkP

javascript - 如何使用 Firebase Cloud Functions 在 DataSnapshot 中查找特定值

我正在尝试制作一个云函数,它将在HTTP请求(通过计时器发送)上触发,这将删除所有具有特定值的child。数据库节点如下所示:activities4GI1QXUJG0MeQ8Bq19WOdCQFo9r1//uidactivity:"hammer"id:someIDnote:"somenote"timestamp:sometimeintervalsince19707IDUiufhiws8939hdfIUHiuhwdi5etc....我想查看所有的事件,如果事件值为“锤子”,我想移除这个child。这是我目前的情况exports.deleteHammerNotifications=func

javascript - create-react-app with node express 获取 %PUBLIC_URL%

我正在尝试使用快速服务器创建react应用程序。在我点击请求时设置服务器后,我得到了GEThttp://localhost:3333/%PUBLIC_URL%/favicon.ico400(错误请求)错误预览它给我URIError:Failedtodecodeparam'/%PUBLIC_URL%/favicon.ico'atdecodeURIComponent()atdecode_param(/home/owaishanif/code/flashcard-app/node_modules/express/lib/router/layer.js:172:12)atLayer.match

javascript - 类型错误 : Cannot read property 'push' of undefined -Express

我已经为使用express路由和创建服务器的nodejs应用程序编写了两个Javascript文件。由于我是初学者,我对此了解不多。当我运行该应用程序时,它向我显示以下错误:-/usr/lib/node_modules/express/lib/router/index.js:472this.stack.push(layer);^TypeError:Cannotreadproperty'push'ofundefinedatFunction.use(/usr/lib/node_modules/express/lib/router/index.js:472:15)atObject.(/hom

javascript - JQuery/JavaScript : refactoring nested functions

我有这个有趣的jQuery函数。它基本上为链接添加了一个点击处理程序,当它被点击时,它将加载一个表单以允许用户编辑内容。表单通过AJAX提交,完成后会显示成功消息。大纲如下;不用说,这很乱。我可以将每个回调作为类方法。还有哪些其他方法可以重构嵌套函数?我也很想知道在重构后是否有方法在父函数中声明的变量仍然保留其值到嵌套函数$('a.edit').click(function(){//..snipped..//getform$.ajax({success:function(){//addform//submithandlerforform$(new_form).submit(functi

javascript - Express.js自定义模板引擎(板 block )

我正在尝试让板模板引擎与express.js一起工作。我最初的尝试是这样的:app.register('.html',{compile:function(str,options){vartemplate=newplate.Template(str);returnfunction(locals){returntemplate.render(locals,function(err,data){returndata;});}}});我看到问题是template.render没有返回任何东西(未定义)而是将数据传递给回调。我不确定在这种情况下如何让它工作,因为Express期望编译函数返回一个

javascript - 函数声明或函数表达式

我刚刚在block作用域中定义函数时遇到了问题。考虑以下程序:try{greet();functiongreet(){alert("MerryChristmas!");}}catch(error){alert(error);}我希望这个程序能提示MerryChristmas!。然而在Firefox中是给我以下ReferenceError:ReferenceError:greetisnotdefined在Opera和Chrome上,它会像我预期的那样提醒问候语。显然,Firefox将block范围内的函数视为FunctionExpression,而Opera和Chrome将其视为Func

javascript - 使用 CSP 在 Web Worker 中启用 'new Function'

我无法让newFunction在WebWorker中工作。我有一个生成WebWorker的HTML页面。这个WebWorker通过newFunction(str)执行代码。我正在尝试在打包的Chrome应用程序中使用它,这需要使用eval类代码的页面在list中明确列为沙盒页面。现在,有两个选择:Do列出要沙盒化的页面。如果这样做,我可以使用newFunction,但我无法生成WebWorker,因为我无法发出任何请求(沙盒页面具有唯一来源)。newWorker(...)抛出一个SECURITY_ERR。newFunction在沙箱中工作newWorker由于唯一来源而在沙箱中失败不要