我已经建立了一种监视系统,其中相机每秒拍摄一张照片,然后将该图像发送到服务器,服务器将覆盖之前的图像。在客户端,我有一个简单的javascript settimeout来每秒加载此图像
$("img").attr("src", "http://mysite/image.jpg?randomString="+new Date().getTime());
Run Code Online (Sandbox Code Playgroud)
但这会导致内存泄漏,并最终导致页面崩溃。如何避免这种情况?在这里缓存问题吗?浏览器是否每秒都缓存每个新图像,这就是内存泄漏的原因吗?
所以我的问题是Controller构造函数执行多次.如果我有2 Directives与特定关联,Controller那么它运行2 + 1,如果3 Directives,然后3 + 1...等等.如果我在该控制器中有一个ajax请求来获取数据,那么它会运行那么多次并不是真正的必要...
为什么会这样?我非常担心它会使所有那些额外的不必要的ajax请求......
HTML:
<span ng-controller="MenuController as MenuCtrl">
<main-menu></main-menu>
</span>
Run Code Online (Sandbox Code Playgroud)
控制器:
var howManyTimes = 0;
angular.module("shredkit", ["myDirectives"])
.controller("MenuController", function(){
++howManyTimes;
console.log("HOW MANY TIMES? THAT MANY: " + howManyTimes )
})
Run Code Online (Sandbox Code Playgroud)
指示:
angular.module("myDirectives", [])
.directive("mainMenu", function(){
return{
restrict:"E", // type of directive - 'E' - element
templateUrl:'templates/main-menu.html',
controller:"MenuController",
controllerAs: "MenuCtrl"
};
})
Run Code Online (Sandbox Code Playgroud) 我有两个表项目和画廊.项目有一个画廊.在库表中,我有一个外键project_id.
Schema::table('galleries', function (Blueprint $table) {
$table->integer("project_id")->unsigned()->nullable()->default(null);
$table->foreign("project_id")
->references("id")
->on("projects")
->onDelete("set null");
});
Run Code Online (Sandbox Code Playgroud)
在Project模型中,我有一个函数可以获得与项目关联的库:
public function gallery()
{
return $this->hasOne("App\Gallery");
}
Run Code Online (Sandbox Code Playgroud)
在创建新项目时,用户从下拉库中选择,然后在保存新项目时,如何更新库表以使用新创建的projects_id
$gallery_id = 2; // user selected gallery 2
$project = new Project();
$project->title = "new project";
$project->save();
Run Code Online (Sandbox Code Playgroud) 在我的循环中,我有一个不断变化的数字 - 我需要弄清楚如何判断数字是增加还是减少:
一些不起作用的伪代码:)
var now:Number;
var then:Number;
function loop():void
{
now = changingNumber;
then = changingNumber;
if (now > then) {
// increasing
}else {
// decreasing
}
}
Run Code Online (Sandbox Code Playgroud)