我正在学习骨干js,试图做一个小项目.
在te页面中,我从cloudflare CDN加载了require.js和text.js.
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js">//</script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require-text/2.0.10/text.js">//</script>
Run Code Online (Sandbox Code Playgroud)
我做了一个名为"Boxes"的骨干视图:
var Boxes = Backbone.View.extend({
// Choose an element.
el : '.content',
render : function () {
// Captur "this" -> the backbone view itself.
var that = this;
$(this.el).html('how do I load a html template here?');
}
});
Run Code Online (Sandbox Code Playgroud)
问题:
当我将text.js插件添加到页面时,我收到以下错误:
不匹配的匿名define()模块:function(module){'use strict'; ......
所以我不能加载require.js和text.js,它甚至在没有任何其他脚本的空白页面上给出了上述错误.
现在,当我在index.html页面中内联编写模板时,我知道如何做到这一点.
我是这样做的:
var Boxes = Backbone.View.extend({
el : '.content',
render : function () {
var that = this; // This backbone view
var template …Run Code Online (Sandbox Code Playgroud) 我有一个通过访问URL到达的主状态http://myapp/validate.
在到达此URL时,在控制器内部进行权限检查,并将用户重定向到两个子状态之一.
这有效,80%满意,但使用一些资源,并在我的应用程序中导致一个小闪烁,因为基本上我加载一个我不使用的视图.
有没有更好的方法来实现这一目标?
有任何想法吗?
angular.module('app.validate').config(['$stateProvider', function($stateProvider) {
$stateProvider
.state('validate', {
url: '/validate',
template: '<ui-view/>',
controller: ['$state', 'HasPermission', function ($state, HasPermission) {
// Here is where I do my logic.
if (HasPermission.get('can-lock-as-admin')) {
$state.go('validate.lock-as-admin');
}
if (HasPermission.get('can-lock-as-clerk')) {
$state.go('validate.lock-as-clerk');
}
}]
})
.state('validate.lock-as-admin', {
templateUrl: 'theUrl',
controller: 'ValidateLockAdminCtrl'
})
.state('validate.lock-as-clerk', {
templateUrl: 'theUrl',
controller: 'ValidateLockClerkCtrl'
})
.state('validate.commit', {
templateUrl: 'theUrl',
controller: 'ValidateCommitCtrl'
});
}]);
Run Code Online (Sandbox Code Playgroud) 使用nodejs和crypto,现在,当用户登录时,我生成一个随机身份验证令牌:
var token = crypto.randomBytes(16).toString('hex');
Run Code Online (Sandbox Code Playgroud)
我知道这不太可能,但两个令牌的可能性很小.
这意味着用户理论上可以在另一个帐户上进行身份验证.
现在,我看到两个明显的方法来传递这个:
你会怎么做?
在config.yml中,我定义了我的集合,如下所示:
collections:
music:
output: false
dancing:
output: false
Run Code Online (Sandbox Code Playgroud)
问题是我将有很多集合,它们会混乱我的根Jekyll文件夹.
有没有办法将所有集合分组到一个文件夹中,例如_collections?
所以,我会:
_collections
_dancing
_music
....
Run Code Online (Sandbox Code Playgroud) 我使用的是ui-router,我有子状态和抽象状态 - 父母.
现在,我希望能够进行一些用户角色管理,我想在一个地方为所有根目录进行管理.
最好的方法是在父级的状态解析对象中.$ stateProvider
在这里,我这样做来管理app宽度认证数据.
问题是,如何从抽象状态的解析函数中获取目标状态?
.state('section', {
abstract: true,
template: '<ui-view/>',
resolve: {
// Auth & role management middleware.
UserData: ['$q', '$stateParams', 'Session', function ($q, $stateParams, Session) {
// HOW DO I GET THE DESTINATION ROUTE HERE.
$state.current.name - returns null
$stateParams - is an empty object.
// ANY IDEAS?
var userData;
userData = Session.getUserData();
if (userData.token) {
return userData;
}
return $q.reject('login');
}]
}
});
Run Code Online (Sandbox Code Playgroud) 捆绑JSPM很简单,这是一个简单的任务:
var exec = require('child_process').exec;
gulp.task('jspmBuild', function (cb) {
exec('jspm bundle-sfx src/app/app.js dist/app.min.js --skip-source-maps', function (err, stdout, stderr) {
cb(err);
});
});
Run Code Online (Sandbox Code Playgroud)
我想做的是,有两个单独的包,一个用于供应商文件,另一个用于实际应用.
那可能吗?
我已经在 Ubuntu VPS 上安装了 Jenkins 并且我正在构建 nodejs,这在某些时候会触发 nginx 中的 502 错误网关并且 Jenkis 服务停止。
构建似乎随机停止,有时在安装 npm 模型时,有时在使用 gulp 等时。
我必须手动重新启动它(sudo service jenkins restart)。
这是构建的控制台输出:
+ jspm -v
0.16.15
Running against local jspm install.
[workspace] $ /bin/sh -xe /tmp/hudson1116016846111302145.sh
+ jspm install
Looking up npm:babel-core
Looking up npm:babel-runtime
Looking up npm:core-js
Updating registry cache...
ok Up to date - babel as npm:babel-core@^5.8.24 (5.8.34)
Looking up github:jspm/nodelibs-fs
Looking up github:jspm/nodelibs-path
Looking up github:jspm/nodelibs-process
Looking up github:systemjs/plugin-json
Looking up npm:process
Looking up npm:path-browserify
Looking …Run Code Online (Sandbox Code Playgroud) 在 express js 中,我有以下代码向 Backbone 发送响应:
if (!user) {
req.session.messages = [info.message];
return res.send(400, howCanIsendTheErrorMessageAlso);
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能同时发送错误消息和错误代码?
Backbone 如何接收它?
有任何想法吗?
在主干中,我有以下代码:
loginModel.save({
username : obj.elEmail.val(),
password : obj.elPassword.val(),
admin : false
}, {
success: function (e) {
console.log('success');
},
error: function (e) {
console.log(e);
}
});
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在谷歌地图中加载某个国家/地区的数据层(这是一个国家/地区的绘图):
map.data.addGeoJson(geoJsonObject);
Run Code Online (Sandbox Code Playgroud)
我很确定没有,但是......有没有办法检查地图的边界是否在数据层的边界内?
(基本上,我想知道,当用户在地图上导航时,当前视口是否位于数据层内);
var bounds = this.map.getBounds();
var sw = bounds.getSouthWest();
Run Code Online (Sandbox Code Playgroud)
也许我可以查询西南方向位置的数据层并检查一些道具。表明我在该数据层内?
或者至少:
有谁知道如何以编程方式获取某个特征对象,知道纬度和经度?
这里谷歌地图使用事件来获取要素对象:
map.data.addListener('click', function(event) {
event.feature.setProperty('isColorful', true);
});
Run Code Online (Sandbox Code Playgroud)
但我不想使用事件。有没有一种方法可以提供点的坐标并获取特征对象? 就像是:
map.getFeature(lat, long).setProperty('isColorful', true);
Run Code Online (Sandbox Code Playgroud) 我有以下数组,其中包含其他数组(它们实际上是html5 canvas的坐标)。
var crossesPos = [[317, 193], [110, 334], [390, 347], [281, 222], [307, 384], [329, 366], [230, 104], [276, 156], [173, 330], [227, 100], [397, 261], [341, 389], [233, 223], [261, 350], [267, 286]]
Run Code Online (Sandbox Code Playgroud)
别说:
x = 317;
y = 193;
Run Code Online (Sandbox Code Playgroud)
在以下函数中,如何从crossesPos中删除数组[317,193]?
function checkForCrosses(x,y){
var position;
jQuery.each(crossesPos, function(){
position = this;
if(x == position[0] && y == position[1]){
// how do I remove the array [317,193] from crossesPos?
}
});
}
Run Code Online (Sandbox Code Playgroud)
!
我正在用 Laravel 构建一个 REST API,我有一个检查令牌的过滤器:
Route::filter('api.auth', function() {
$token = Request::header('X-CSRF-Token') ? Request::header('X-CSRF-Token') : '';
if (empty($token)) {
return Response::json(
['message' => 'A valid API key is required!'],
401
);
};
$user = User::where('token', '=', $token);
if ($user->count()) {
$user = $user->first();
Auth::login($user);
} else {
return Response::json(
['message' => 'Your token has expired!'],
401
);
};
});
Run Code Online (Sandbox Code Playgroud)
如果一切正常,过滤器将登录用户 uth::login($user);
我怎样才能只为 1 个请求登录他?
由于每次请求都会检查此过滤器,因此我认为每次都将用户注销会更好。
我在 Laravel 的文档中看到过这个,不知道如何应用它:
if (Auth::once($credentials))
{
//
}
Run Code Online (Sandbox Code Playgroud)
我的回复中可以有回调吗?我可以在哪里注销用户?
/*
获取所有产品。*/ 公共函数 getProducts() {
$products = …Run Code Online (Sandbox Code Playgroud) 我正在编写一个脚本来查询div中的所有dom元素并用一些自定义标记替换它们 - 脚本应该可以工作......但显然它没有,我不知道为什么.
这是js:
var data = {
SPAN: function(content) {
return '|span|' + content + '|span|'
},
DIV: function(content) {
return '|div|' + content + '|div|'
},
P: function(content) {
return '|p|' + content + '|p|'
},
H2: function(content) {
return '|h2|' + content + '|h2|'
},
}
$(document).ready(function() {
// Iterate through each element of the dom.
$('#result *').each(function () {
var type = $(this)[0].tagName;
var content = $(this).html();
if (data[type]) var result = data[type](content);
if (result) $(this).replaceWith(result); …Run Code Online (Sandbox Code Playgroud) 我已经整理了一个小测试,有人可以解释为什么JavaScript会执行以下操作?
为什么会testArr继承修改newArray?
var TestClass = function() {
this.testArr = [10,11];
this.addToArray = function() {
var newArray = this.testArr;
newArray.push(12);
}
}
var testClass = new TestClass();
testClass.addToArray();
console.log(testClass.testArr); // will be [10, 11, 12]
Run Code Online (Sandbox Code Playgroud) javascript ×5
node.js ×3
angularjs ×2
backbone.js ×2
jquery ×2
angular-ui ×1
collections ×1
cryptojs ×1
express ×1
geojson ×1
google-maps ×1
gulp ×1
jekyll ×1
jenkins ×1
jspm ×1
laravel ×1
nginx ×1
requirejs ×1
systemjs ×1
ubuntu ×1