我有一个问题,Grunt Watch目前没有在编译错误纠正后重新运行任务.
我收到错误消息,但在纠正错误之后,grunt说文件已经更改,但在该点之后没有运行任务.
Grunt文件:
watch: {
less: {
files: ['public/assets/less/**/*.less'],
tasks: ['css'],
options: {
atBegin: true,
nospawn: true
}
},
scripts: {
files: [
'public/assets/js/homepage.js'
],
tasks: ['jsApp'],
options: {
nospawn: true,
}
}
},
Run Code Online (Sandbox Code Playgroud)
错误日志:
>> ParseError: Unrecognised input in public/assets/less/template.less on line 114, column 31:
>> 114 @media screen and (max-width: 767px) {
>> 115 left: 0;
Warning: Error compiling public/assets/less/main.less
// ----- Corrected the file here, saved again -----
>> File "public/assets/less/template.less" changed.
Run Code Online (Sandbox Code Playgroud)
文件结束.在此之后没有任何事情.
我正在尝试从PHP对象中打开数据(如下所示),但我希望能够在JavaScript中访问这些数据以在图形库中使用.
有问题的对象:

我需要做的是将其转换为JSON编码对象以便在Javascript中使用.
我尝试在Symfony中使用twig通过以下方式执行此操作:
{% set playerStats = match.getStatsPlayers().getValues() }%
{% dump(playerStats) %} // This is what you see above
var playerStats = {{ playerStats|json_encode }};
console.log(playerStats);
Run Code Online (Sandbox Code Playgroud)
控制台显示:

这就是我撞在墙上的地方.我在哪里可以访问这些属性的值?
作为一种低效的方式,我通过以下方式设法将其变为JavaScript对象:
{% for p in playerStats %}
playerStats.push({ 'id': {{p.playerID}}, 'playerName': '{{p.playerName}}', 'playerOutfit': {{p.playerOutfit}}, 'playerFaction': {{p.playerFaction}}, 'playerKills': {{p.playerKills}}, 'playerDeaths': {{p.playerDeaths}}, 'playerTeamKills': {{p.playerTeamKills}}, 'playerSuicides': {{p.playerSuicides}} });
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
这样做我觉得有点脏.必须有更好的方法来做到这一点吗?
提前致谢!
我正在尝试做一些在PHP中非常简单但在树枝中却不那么容易的事情。
基本上,我需要调用一个类方法,但是我需要能够定义要通过字符串调用的方法。
我有3种方法:getControlvs,getControlnc和getControltr。但是,为了调用这些方法,我需要一个单独的变量来确定要调用的方法。
这是我现在正试图调用的:
{% set neutPer = key.getControl~neutFaction %}
Run Code Online (Sandbox Code Playgroud)
其中neutFaction可以是“ vs”,“ nc”或“ tr”。
这似乎只触发了key.getControl,仅此而已,串联丢失了。
有任何想法吗?
提前致谢!
我对Twig决定不允许通过设置数组和对象属性的值感到非常困惑set.
例如,以下代码将出错:
{% set entry.depth = 1 %}
会导致错误:
Unexpected token "punctuation" of value "." ("end of statement block" expected)
另外以下方式也会出错(我知道twig不喜欢使用):
{% set entry['depth'] = 1 %}
所以这实际上意味着我们无法改变对象和数组的属性.坦率地说,我发现这很离奇.
有人可以解释一下这背后的决定吗?也许如果我得到一个技术原因为什么它不可能它可能会让它不那么令人困惑.
编辑:感谢您的解决方案,我更多的是在你必须使用合并而不仅仅是能够覆盖变量的事实背后的推理.