简体   繁体   English

将比较结果分配给变量 javascript

[英]assign result of comparison to variable javascript

If I do that:如果我这样做:

var importance_not_matched = {{item.this_article_importance}} <= article_importance;

It seems to work but in my IDE (Pycharm) I have errors: "Expression expected" on the "<=" and "underterminated statment" on the final ";"它似乎有效,但在我的 IDE (Pycharm) 中,我有错误:“<=”上的“Expression expected”和最终“;”上的“underterminated statment”

I'm using flask, item.this_article_importance is an int我正在使用烧瓶, item.this_article_importance 是一个 int

I solved my issue by changing to:我通过更改为解决了我的问题:

year_not_matched = {{item.this_article_year <= article_year}};

I don't understand why it's better yet though我不明白为什么它更好

Depending on the type of value that is {{ item.this_article_importance }} you may have to use filter |safe , so that django does not escape it.根据{{ item.this_article_importance }}值的类型,您可能必须使用 filter |safe ,以便 django 不会对其进行转义。

Something like this:像这样的东西:

var importance_not_matched = {{ item.this_article_importance|safe }} <= article_importance;

You can verify that both variables really have the desired value, even the type, to ensure where the error comes from.您可以验证两个变量是否确实具有所需的值,甚至类型,以确保错误来自何处。

var this_article_importance = {{ item.this_article_importance|safe }};
console.log(typeof(this_article_importance), this_article_importance);

It's hard to know more without more information.没有更多信息就很难知道更多。 You can review this question where the topic is discussed.您可以在讨论该主题的地方查看此问题

I solved my issue by changing to:我通过更改为解决了我的问题:

year_not_matched = {{item.this_article_year <= article_year}}; year_not_matched = {{item.this_article_year <= article_year}};

I don't understand why it's better yet though我不明白为什么它更好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM