无法在Django模板+ Angularjs变量中显示项目列表

时间:2022-01-05 20:22:53

I have below code in my template which displays the tags that were entered via input text using Angularjs in Django template.

我的模板中有以下代码,它显示了使用Django模板中的Angularjs通过输入文本输入的标记。

<div id="tags" style="border:none;width:370px;">
  {% for cat in categories %}            
  <span class="tag" ng-repeat="data in dataset" id="4" 
                    ng-click="removeData_sk($index)">
    {%verbatim%} {{data.name}} {%endverbatim%} {{ cat.sname }}
  </span>
  {% endfor %}
  <div>    
    <input type="text" style="margin-left:-5px;" id="inptags" value="" 
           placeholder="Add ur 5 main categories (Enter)" 
           ng-model="inputVal" ng-keypress="skEnter($event)"/>
  </div>
</div>            

In the above span tag, {{data.name}} is angularjs variable -> that is set via the input text. And {{ cat.sname }} is my Django template variable -> which basically has list of values from categories (from the server).

在上面的span标记中,{{data.name}}是angularjs variable - >,它是通过输入文本设置的。而{{cat.sname}}是我的Django模板变量 - >它基本上有来自类别(来自服务器)的值列表。

This doesn't show me the list of categories that were returned from server as spans.. What am I missing?

这没有向我显示从服务器返回的类别列表。我错过了什么?

How can I display the list of spans that were returned from server.. and at the same time, how can I use angularjs variable as and when required.. Basically, I need to have these two kinds of variables synced.

如何显示从服务器返回的跨度列表..同时,如何在需要时使用angularjs变量。基本上,我需要同步这两种变量。

I used Angularjs in Django powered site first time.

我第一次在Django驱动的站点中使用了Angularjs。

Earlier without angularjs, code looks to be like this -

早期没有angularjs,代码看起来像这样 -

        <div id="tags" style="border:none;margin-left:25px;width:70%;">
                {% for cat in categories %}            
              <span class="tag" id="4">{{ cat.sname }}</span>
                {% endfor %}
              <div>    
                <input type="text" style="margin-left:-5px;overflow:hidden" id="inptags" value="" placeholder="Add ur 5 main categories (enter ,)" />            
              </div>
        </div> 

1 个解决方案

#1


0  

Adding this just in case if it helps someone in need.

添加这个以防万一它可以帮助有需要的人。

I solved it by assigning the array to my dataset variable in my Angularjs. It got the list of categories as spans.

我通过将数组分配给Angularjs中的数据集变量来解决它。它将类别列表作为跨度。

$scope.dataset=d1_init;

d1_init is my javascript variable, which contains the list of categories that were assigned from django tags.

d1_init是我的javascript变量,它包含从django标签分配的类别列表。

So my code in the Django template is -

所以我在Django模板中的代码是 -

<span class="tag" ng-repeat="data in dataset" id="4" ng-click="removeData_sk($index)"> {%verbatim%} {{data.name}} {%endverbatim%} </span>

#1


0  

Adding this just in case if it helps someone in need.

添加这个以防万一它可以帮助有需要的人。

I solved it by assigning the array to my dataset variable in my Angularjs. It got the list of categories as spans.

我通过将数组分配给Angularjs中的数据集变量来解决它。它将类别列表作为跨度。

$scope.dataset=d1_init;

d1_init is my javascript variable, which contains the list of categories that were assigned from django tags.

d1_init是我的javascript变量,它包含从django标签分配的类别列表。

So my code in the Django template is -

所以我在Django模板中的代码是 -

<span class="tag" ng-repeat="data in dataset" id="4" ng-click="removeData_sk($index)"> {%verbatim%} {{data.name}} {%endverbatim%} </span>