我正在将在Yii1中开发的旧应用程序迁移到Yii2.
我以前在控制器中有一个数组,它存储了我需要作为JavaScript发送到前端的所有变量:
public $jsVars;
public function toJSObject($params){
$this->jsVars = array_merge($this->jsVars, $params);
}
private function printJSVarsObject(){
//convert my php array into a js json object
}
Run Code Online (Sandbox Code Playgroud)
当我需要在Javascript中公开变量时,我只想在View或Controller中使用$ this-> toJSObject.
然后,在控制器中我也曾经有过:
public function beforeRender($view){
$this->printJSVarsObject();
}
Run Code Online (Sandbox Code Playgroud)
在Yii2中,我必须使用自定义视图配置View组件,然后附加事件:
namespace app\classes;
use yii\base\Event;
use yii\helpers\Json;
Event::on(\yii\web\View::className(), \yii\web\View::EVENT_END_BODY, function($event) {
$event->sender->registerJSVars();
});
class View extends \yii\web\View {
public $jsVars = [];
public function addJsParam($param){
$this->jsVars = array_merge($this->jsVars, $param);
}
public function registerJSVars() {
$this->registerJs(
"var AppOptions= " . Json::htmlEncode($this->jsVars) . ";",
View::POS_END,
'acn_options'
);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用VSC开发一个基本的angular2应用程序.代码是用TypeScript编写的.它是一个基本的todo应用程序,所有代码(.ts,js,.js.map)都在app /子文件夹中.
这是Run的launch.json配置:
{
"name": "Run",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/lite-server/bin/lite-server",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
Run Code Online (Sandbox Code Playgroud)
当我运行它时,应用程序加载chrome,但我的断点都不起作用.当我悬停一个断点时,我看到"断点被忽略,因为找不到生成的代码(源映射问题?)."
我在/app/todo.component.ts中有一个断点.在我的/app/todo.component.js.map中我可以看到:
"file":"todo.component.js","sourceRoot":"/Users/xxx/Documents/webs/angular2-todo/app/","sources":["todo.component.ts"],"names":[],"mappings":";;;;;;;;;;
Run Code Online (Sandbox Code Playgroud)
源根和来源对我来说似乎没问题.
有任何想法吗?
非常简单,容器必须使其子级拉伸(按原样),但子级 div 的内容必须与底部对齐,与 flex-end 相同,但同时保持高度。
关于如何做到这一点有什么想法吗?
看看这支笔: http://codepen.io/anon/pen/NAjRvo
.container {
height: 100px;
background: BurlyWood;
display: flex;
align-items: stretch;
}
.item{
flex:1;
margin: 4px;
background: Crimson;
}
.item p {
margin: 0;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="item">
<p>lorem</p>
</div>
<div class="item">
<p>ipsum</p>
</div>
<div class="item">
<p>dolor</p>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
这是我用vue创建任何东西的第一次尝试。
我正在尝试创建一个无需输入即可显示值的表单,然后单击,将显示输入。我设法使模型“工作”,但是我不确定这是否是正确的方法。我不太确定:
Vue.nextTick(function() {
document.getElementById(field.id).focus();
});
Run Code Online (Sandbox Code Playgroud)
另一方面,是否有推荐的输入验证库或其他东西?
我真的很感谢这里的任何指导方针:wink:
谢谢!
我试图让我的favicon可缓存为yslow suggets.
我的网站是http://www.tucoaster.com/favicon.ico
出于某种原因,favicon的内容类型是text/plain.我正在使用apache2,并且在我的.htaccess中
ExpiresByType text/plain "access plus 30 days"
ExpiresByType image/x-icon "access plus 30 days"
ExpiresByType image/ico "access plus 30 days"
Run Code Online (Sandbox Code Playgroud)
注意:Javascript和css标头发送正常.
有什么建议吗?