![](/img/trans.png)
[英]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.