[英]How to assign the result of a conditional decision to a variable in javascript
[英]assign result of comparison to variable javascript
如果我这样做:
var importance_not_matched = {{item.this_article_importance}} <= article_importance;
它似乎有效,但在我的 IDE (Pycharm) 中,我有错误:“<=”上的“Expression expected”和最终“;”上的“underterminated statment”
我正在使用烧瓶, item.this_article_importance 是一个 int
我通过更改为解决了我的问题:
year_not_matched = {{item.this_article_year <= article_year}};
我不明白为什么它更好
根据{{ item.this_article_importance }}
值的类型,您可能必须使用 filter |safe
,以便 django 不会对其进行转义。
像这样的东西:
var importance_not_matched = {{ item.this_article_importance|safe }} <= article_importance;
您可以验证两个变量是否确实具有所需的值,甚至类型,以确保错误来自何处。
var this_article_importance = {{ item.this_article_importance|safe }};
console.log(typeof(this_article_importance), this_article_importance);
没有更多信息就很难知道更多。 您可以在讨论该主题的地方查看此问题。
我通过更改为解决了我的问题:
year_not_matched = {{item.this_article_year <= article_year}};
我不明白为什么它更好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.