Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

JS und Literalproblem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
escape3D
Smarty n00b


Joined: 10 Feb 2018
Posts: 1

PostPosted: Sat Feb 10, 2018 12:23 pm    Post subject: JS und Literalproblem Reply with quote

Hallo Community,

ich habe ein JS-Problem und bekomme das nicht in den Griff.
Inner halb meines Javascripts müsste eine Foreachweisung eingebunden werden. Jedoch hat das Javascript selbst eine geschweifte Klammer und dieses scheint Probleme zu veruresachen. Vielleicht kennt jemand eine Lösung für das Problem? Innerhalb von JS-ARRAY-DATA müsste die Foreachweisung rein. Das Literal öffnen und wieder schliessen innerhalb des JS bringt leider kein Resultat.




Code:

{foreach from=$var item=var}{$var.hour} {$var.value}{/foreach}


Code:

{literal}
   <script type="text/javascript">
      $(document).ready(function(){

      ...

         data: [
               {hours: '02', value: 215000},
               {hours: '02', value: 35000},
               {hours: '03', value: 1000},
               {hours: '04', value: 120000}
               ],

      ...
      
      });

   });
   </script>      
{/literal}



Ich würde mich mich sehr über eure Hilfe freuen.
Gruße escape
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Sat Feb 10, 2018 9:22 pm    Post subject: Reply with quote

Hey,

deiner foreach-Schreibweise nach, vermute ich mal, dass du Smarty2 und nicht Smarty 3 einsetzt??? Denn du verwendest die "alte" schreibweise.

Nichtsdestotrotz hast du einen kleinen Denkfehler in deiner foreach:

"from" und "item" ist die selbe Variable, was also nicht klappen kann. Denn du verwendest als array var und sagst jede iteration der Daten soll in die variable var eingefügt werden, was also bedeuten würde, du würdest dein array überschreiben...

Ansonsten kannst du mal folgendes probieren:



Code:


{literal}
   <script type="text/javascript">
      $(document).ready(function(){
         data: [
               {hours: '{/literal}{$hours}', value: {$value}{literal} },
     
      });

   });
   </script>     
{/literal}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP