我正在研究Gruntfile配置.我需要遍历所有匹配模板变量中定义的模式的文件,如下所示:
module.exports = {
templates: {
all: ['src/templates/**/*.html*’]
}
};
Run Code Online (Sandbox Code Playgroud)
我需要将这些文件中的每一个用作此处定义的'swapper'目标上名为'files'的数组中的值:
task-config :{
swapper : {
files: {
// foreach (file in templates) {
// ‘destination/‘ + “‘“ + file.ToString() + “‘“ : ‘file.ToString()’
// if (isNotLastFile()) {
// appendComma()
// }
// }
},
tasks: ['jshint:ignore_warning:test' ],
options: {
encodeSpecialChars: true
}
}
}
Run Code Online (Sandbox Code Playgroud)
我很难让语法正确.甚至可以做我在Grunt尝试的事情吗?或者,我需要以不同的方式去做吗?
谢谢
我是Java的新手.我一直在研究一个使用Maven和Java 1.7的项目.在我的项目中,我有一个HashMap.我想将此HashMap输出到JSON.目前推荐的方法是什么?
当我进行谷歌搜索时,我会得到很多选择(即杰克逊).但是,我不确定我应该使用什么.另外,我想使用可通过Maven访问的库.
谢谢,
我正在研究ASP.NET MVC 3应用程序.我主要来自ASP.NET WebForms背景.我正在开发一个具有复杂布局方案的应用程序.因此,我希望将所有布局代码都放在_Layout.cshtml中.我的挑战是,每个页面都有自定义的javascript逻辑.我发现如果这个JavaScript包含在我的页面中间,它就不起作用.所以我想做的就是把它移到其他地方.但为了做到这一点,我需要类似于ASP.NET WebForms PlaceHolder控件的东西.理想情况下,我希望能够做到这样的事情:
<body>
<div id="myLayout" style="background-color:Gray; height:100%;">
<div id="myContent" style="background-color:Silver;">
@RenderBody()
</div>
<div id="myFooter" style="background-color:Silver;">
Footer
</div>
</div>
@RenderScript()
</body>
Run Code Online (Sandbox Code Playgroud)
有没有办法让我这样做?或者我是否必须单独编写每个页面?
谢谢!
我有一个包含 bootstrap 的 ASP.NET MVC 应用程序。我的目录结构如下所示:
/
/App_Start
BundleConfig.cs
/Content
app.css
bootstrap.min.css
/Fonts
glyphicons-halflings-regular.eot
glyphicons-halflings-regular.svg
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
glyphicons-halflings-regular.woff2
Run Code Online (Sandbox Code Playgroud)
我需要将 Bootstrap 捆绑到我的应用程序中。在我的 BundleConfig.cs 文件中,我有以下内容:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/public/bundles/css")
.Include("~/Content/bootstrap.min.css")
.Include("~/Content/app.css")
);
bundles.Add(new ScriptBundle("~/public/bundles/scripts")
.Include("~/Scripts/jquery-2.1.4.min.js")
.Include("~/Scripts/jquery-ui-1.11.4.min.js")
.Include("~/Scripts/bootstrap.min.js")
.Include("~/Scripts/jquery.validate.min.js")
.Include("~/Scripts/jquery.validate.unobtrusive.min.js")
);
}
Run Code Online (Sandbox Code Playgroud)
当捆绑关闭时,一切都呈现良好。当我打开捆绑时,除了字体图标之外,一切都呈现良好。当我查看控制台窗口时,我看到与字体图标相关的 5 404 错误。它就像尝试引用字体文件,如下所示:
http://localhost:9090/public/fonts/glyphicons-halflings-regular.woff2
然而,它们并不存在于公共目录中。我不知道如何解决这个问题。
我正在开发一个使用 Express 的 Node 应用程序。在此应用程序中,我需要获取整个网址。例如,如果用户访问,我需要在我的代码中http://www.my-example.com/path/to-page查看。http://www.my-example.com/path/to-page目前,我在代码中使用以下内容:
this.url = req.protocol + '://' + req.get('host') + req.originalUrl
上述方法有效。然而,我注意到我的应用程序由于这一行而受到了几毫秒的影响。我不确定是因为字符串连接还是get函数请求。不管怎样,对象本身似乎应该有一些东西req可以给我完整的 URL。是不是有什么东西我只是忽略了?
谢谢!
我有一些我用Jasmine测试的JavaScript .这时,我的一个套房看起来像这样:
var library = require('../library');
describe('My App -', function() {
afterEach(function(done) {
// some clean up code goes here
library.cleanUp(done);
done();
});
describe('Test Operation 1 -', function() {
beforeEach(function(done) {
library.init(done);
});
it('should load fine', function() {
if (library) {
expect(true).toBe(true);
} else {
expect(false).toBe(true);
}
});
var parameters = [1, 8.24, -1];
var results = [5, 4, 0];
// [TODO]: Create tests here
});
});
Run Code Online (Sandbox Code Playgroud)
有我生成我的规格的方式parameters和results数组?换句话说,在运行时,我基本上想要动态运行:
it('should be 5 when parameter is …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Express 的 Node.js 应用程序。在那个应用程序中,我有一个看起来像这样的块:
const app = require('./app');
const port = process.env.PORT || 8080;
const server = app.listen(port);
server.on('listening', () =>
console.log(`Application launched on ${app.get('host')}:${port}`)
);
Run Code Online (Sandbox Code Playgroud)
这成功地工作。当listening事件被触发时,它会成功打印消息。我的问题是,当我的服务器停止/关闭时,我可以监听任何事件吗?或者当服务器停止侦听时?
我想在这种情况下进行一些清理。
我是Node.js的新手。我正在尝试创建一个Web服务器,该服务器将1)提供静态html网页; 2)提供基本的JSON / REST API。管理层告诉我,我必须使用RESTIFY(我不知道为什么)。目前,我有以下内容:
var restify = require('restify');
var fs = require('fs');
var mime = require('mime');
var ecstatic = require('ecstatic');
var ws = restify.createServer({
name: 'site',
version: '0.2.0'
});
ws.use(restify.acceptParser(server.acceptable));
ws.use(restify.queryParser());
ws.use(restify.bodyParser());
ws.use(ecstatic({ root: __dirname + '/' }));
ws.get('/rest/customers', findCustomers);
ws.get('/', ecstatic({ root:__dirname }));
ws.get(/^\/([a-zA-0-9_\.~-]+\/(.*)/, ecstatic({ root:__dirname }));
server.listen(90, function() {
console.log('%s running on %s', server.name, server.url);
});
function findCustomers() {
var customers = [
{ name: 'Felix Jones', gender:'M' },
{ name: 'Sam Wilson', gender:'M' },
{ name: …Run Code Online (Sandbox Code Playgroud) 我有兴趣通过GitHub为Zurb Foundation项目做贡献.但是,我无法弄清楚如何构建项目.我已成功从https://github.com/zurb/foundation.git克隆了存储库.
当我从命令行运行时grunt,收到一条错误消息:
grunt-cli: The grunt command line interface. (v0.1.11)
Fatal error: Unable to find local grunt.
Run Code Online (Sandbox Code Playgroud)
我然后运行npm install grunt,并npm install grunt-cli通过命令行.执行此操作后,我收到一条错误消息:
Loading "Gruntfile.js" tasks...ERROR
>> Error: Cannot find module 'highlight.js'
Warning: Task "default" not found. Use --force to continue.
Run Code Online (Sandbox Code Playgroud)
但是,当我打开Gruntfile.js时,我可以看到确实存在"默认"任务.我究竟做错了什么?我真的想弄清楚如何在我的本地环境中建立Zurb Foundation,以便我可以开始贡献.
谢谢
我有一些匹配小数点后一定位数的代码。目前,我有以下内容:
var input = getValueFromUser();
var count = getCount();
var x = Number(input.toString().match(/^\d+(?:\.\d{0,1})?/));
alert(x);
Run Code Online (Sandbox Code Playgroud)
此方法始终获取小数点后的第一个数字。但是,我想用中的值替换正则表达式中的1 count。我怎么做?我尝试了以下方法:
var pattern = '/^\d+(?:\.\d{0,' + count + '})?/';
var x = Number(input.toString().match(pattern));
Run Code Online (Sandbox Code Playgroud)
但是,现在,我总是得到0的x。
我有一个网页,我试图通过Webdriver I/O进行测试.我的问题是,如何通过测试点击几个链接?目前,我有以下内容:
var webdriverio = require('webdriverio');
var client = webdriverio.remote(settings).init()
.url('http://www.example.com')
.elements('a')
.then(function(links) {
for (var i=0; i<links.value.length; i++) {
console.log('Clicking link...');
var link = links.value[i].ELEMENT;
link.click().then(function(result) {
console.log('Link clicked!');
});
}
})
;
Run Code Online (Sandbox Code Playgroud)
执行上述操作后,我在链接上收到"click is not a function"的错误消息.当我打印link到控制台时,它看起来像JSON,这是有意义的,因为文档说元素函数返回WebElement JSON对象.不过,我只想弄清楚如何点击此链接.
如何做到这一点?
谢谢!
javascript ×4
node.js ×4
express ×2
gruntjs ×2
asp.net-mvc ×1
jasmine ×1
java ×1
json ×1
regex ×1
restify ×1
webdriver-io ×1