社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

[精华] Django模板中引入了JS变量,请问如何比较两者的大小

TMAC狂热-weibo • 9 年前 • 8745 次点击  

在Django中引入了JQcloud标签云插件,需要比较JS变量与Django模板变量的关系 求解~

<script type="text/javascript">
  /*!
   * Create an array of word objects, each representing a word in the cloud
   */

     //var list=[["Java", 8], ["Android", 0], ["数据库", 1], ["算法", 0]];
     var list = {{ tagCloud|safe}};


     var word_array = new Array(); 
     for( i in list )
      {
        var temp = list[i][0];

        {% for j in tags %}
         //tags = ["Java","Android","数据库","算法"]

            {% if j == temp %}
            //比较JS变量与Django模板变量的大小  这种方法表示不可行
            //求解决

             word_array.push({text:list[i][0],weight:list[i][1],link:{ href: "{% url 'tagDetail' j %}"}});

            {% endif %}

        {% endfor %}


            //word_array.push({text:list[i][0],weight:list[i][1],link: "http://www.tmackan.com/articleTag/" + temp});


      }


   /*var word_array = [
      {text: "Lorem", weight: 15},
      {text: "Ipsum", weight: 9, link: "http://jquery.com/"},
      {text: "Dolor", weight: 6, html: {title: "I can haz any html attribute"}},
      {text: "Sit", weight: 7},
      {text: "日了", weight: 15}
      // ...as many words as you want
  ];*/

  $(function() {
    // When DOM is ready, select the container element and call the jQCloud method, passing the array of words as the first argument.
    $("#example").jQCloud(word_array);
  });
</script>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1136
 
8745 次点击  
文章 [ 14 ]  |  最新文章 9 年前