我正在使用react-router处理反应应用程序.我有一个项目页面,其中包含如下网址:
myapplication.com/project/unique-project-id
Run Code Online (Sandbox Code Playgroud)
当项目组件加载时,我从componentDidMount事件触发该项目的数据请求.我现在遇到一个问题,如果我直接在两个项目之间切换,所以只有id改变这样......
myapplication.com/project/982378632
myapplication.com/project/782387223
myapplication.com/project/198731289
Run Code Online (Sandbox Code Playgroud)
componentDidMount不会再次触发,因此不会刷新数据.我应该使用另一个生命周期事件来触发我的数据请求,还是采用不同的策略来解决这个问题?
出于某种原因,当我点击它们时,我的onClick处理程序正在向我的URL添加一个空查询参数.我能够通过将event.preventDefault添加到我的事件处理程序来解决问题,但我想更好地了解实际发生的情况以及这是否是正确的解决方案.对于上下文,下面的代码是测试某些OAuth 2功能的简单组件.onClick处理程序只会触发回流操作.你会看到我已经为所有人添加了e.preventDefault().如果没有这个修复,只要我触发其中一个函数,我的url就会从http:// localhost:3000 /#/ signIn更改为http:// localhost:3000 /?#/ signIn.我也在使用react-router.
// dependencies -------------------------------------------------------
import React from 'react';
import hello from '../../libs/hello';
import Actions from '../../actions/Actions';
import UserStore from '../../stores/userStore';
var Signin = React.createClass({
// life cycle events --------------------------------------------------
componentDidMount: function () {
},
render: function () {
return (
<form>
<h2>Sign in with Google</h2>
<button className="btn btn-primary" onClick={this._signIn} >
<i className="fa fa-google" />
<span> Google</span>
</button>
<button className="btn btn-info" onClick={this._logToken} >Log Token</button>
<button className="btn btn-warning" onClick={this._signOut}>Sign Out</button>
</form> …Run Code Online (Sandbox Code Playgroud) 我正在使用UI-Router和angular bootstrap-ui.我有一个状态设置来创建模态'onEnter'.当我试图关闭模态'onExit'时,我现在遇到了问题.这是基本状态.当输入'items.detail'时它将打开一个模态,当该模态被关闭或解除时它将转换为'items'.
.state('items.detail', {
url: '/{id}',
onEnter: function ($stateParams, $state, $modal, $resource) {
var modalInstance = $modal.open({
templateUrl: 'views/modal/item-detail.html',
controller: 'itemDetailCtrl'
})
.result.then(function () {
$state.transitionTo('items');
}, function () {
$state.transitionTo('items');
});
}
})
Run Code Online (Sandbox Code Playgroud)
我试过像这样使用onExit处理程序.但是无法从该处理程序访问modalInstance或modal所在的范围.我尝试注射的所有东西都是未定义的.
.state('items.detail', {
url: '/{id}',
onEnter: function ($stateParams, $state, $modal, $resource) {
var modalInstance = $modal.open({
templateUrl: 'views/modal/item-detail.html',
controller: 'itemDetailCtrl'
})
.result.then(function () {
$state.transitionTo('items');
}, function () {
$state.transitionTo('items');
});
},
onExit: function ($scope) {
controller: function ($scope, $modalInstance, $modal) {
$modalInstance.dismiss();
};
}
}) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的角度应用程序上实现一些缓存清除,它仍然允许缓存,但在我们将新代码推送到生产时随时打破它.到目前为止,我的设置涉及使用grunt缓存破解程序https://www.npmjs.org/package/grunt-cache-breaker挖掘我的连接的角度app.js文件,并将查询参数追加到以.html文件结尾的任何字符串延期.我也为我使用ng-include的任何模板文件执行此操作.这样做的一个复杂因素是,现在我需要先将模板文件复制到dist /目录,这样我就可以安全地.gitignore缓存被破坏的版本,而不必每次缓存缓存时都提交我的所有模板(并产生冲突) .
我的问题不是如何做到这一点,而是更多的理智检查是否这是一种避免新代码模板缓存的实用方法?我已经看到了在角度中禁用模板缓存的示例,但似乎在文件不更改时,我希望在代码推送之间使用它.
其他人如何解决这个问题?
我正在尝试在解压缩时读取gzip压缩文件的一部分,这样我就可以解析头部内容而无需读取不必要的字节.我之前使用过这个工作,fs.read()同时传递选项只读取前500个字节,然后zlib.gunzip()在从二进制数据解析头部之前使用解压缩内容.
这个工作正常,直到节点v5.0.0修补了一个错误,以确保zlib在截断的输入上引发错误(https://github.com/nodejs/node/pull/2595).
现在我从zlib收到以下错误.
Error: unexpected end of file
Run Code Online (Sandbox Code Playgroud)
如何知道我在截断输入而不抛出错误的情况下解压缩这个部分文件.我认为使用流可能更容易,所以我写了以下内容.
var readStream = fs.createReadStream(file.path, {start: 0, end: 500});
var gunzip = zlib.createGunzip();
readStream.pipe(gunzip)
.on('data', function(chunk) {
console.log(parseBinaryHeader(chunk));
console.log('got %d bytes of data', chunk.length);
})
.on('error', function (err) {
console.log(err);
})
.on('end', function() {
console.log('end');
});
Run Code Online (Sandbox Code Playgroud)
我的parseBinaryHeader()函数返回正确的标题内容,所以我知道它是解压缩但它仍然在输入结束时抛出错误.我可以添加错误监听器来处理错误,并且不做任何事情,但这似乎并不理想.
有任何想法吗?
我正在尝试将条纹集成到一个角度项目中.我正在我的控制器中运行条带方法,我想从回调更新各种范围值.我相信有一些范围问题我不理解.我可以在回调中控制记录我的范围变量,再次更新它们和控制台日志以查看新值.但是,如果我尝试在回调之外再次记录变量,我会得到旧值,然后新值不会进入我的视图.我也试过将我的$ scope基元移动到$ scope对象无济于事.这是一个例子.
app.controller('checkoutCtrl', function ($scope) {
// default values
$scope.receipt = {};
$scope.paymentSuccess = false;
$scope.saveCardForFuture = true;
Stripe.card.createToken($scope.card, function (status, res) {
$scope.receipt = res.data;
$scope.paymentSuccess = true;
if ($scope.saveCardForFuture === true) {
// save card token
}
// tests cases
console.log($scope.saveCard) //logs undefined
console.log($scope.receipt) //logs the response data
console.log($scope.paymentSuccess) //logs true
});
// timeout long enough to wait for stripe response
$timeout(function() {
console.log($scope.receipt); //logs {}
console.log($scope.paymentSuccess) //logs false
}, 1000);
});
Run Code Online (Sandbox Code Playgroud)
注意:Stripe不作为控制器依赖项传递,我只是从我的html索引页面全局包含它.我还没有找到一种方法将其作为可注射依赖项包含在内,但必须有更好的方法.
尝试从快递3更新到表达4我的文件上传路径开始返回req.files为undefined.我已将中间件安装为单独的依赖项,因为它们未包含在express中,并且我已停止使用已删除的app.configure()方法.这是我的主服务器文件
// dependencies ==========================================================================
var express = require('express'); // framework
var mongoose = require('mongoose'); // mongo driver
var morgan = require('morgan'); // request logger
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var fs = require('fs');
var app = express(); // initialize as 'app'
// configuration =========================================================================
mongoose.connect('mongodb://localhost/constellates');
var port = 4000; // set port number for app
app.use(bodyParser()); // pull information from html in POST
app.use(express.static(__dirname + '/public')); // set static files directory
app.use(morgan('dev')); // log every request to …Run Code Online (Sandbox Code Playgroud) angularjs ×3
javascript ×3
node.js ×2
reactjs ×2
caching ×1
express ×1
postback ×1
react-router ×1
templates ×1
zlib ×1