search

Home  >  Q&A  >  body text

How to loop assignment in thinkphp in js

Like the title
For example, what I want to achieve is that I pass an array through the tp framework and I want to turn it into an array object

var data = [];
var countObj ={};
var tagNumObj ={};
for (var i = 0; i < 7; i ) {

          
 var count = {$tagGroupArray[i]['count']};
 var tagName = "{$tagGroupArray[i]['tagName']}";
 countObj = {'count':count};
 tagNumObj = {'tagName':tagName};
 data[i] = countObj;
 data[i] = tagNumObj;

}
console.log(data);

This is how it is displayed
var count = ;
var tagName = "";
countObj = {'count':count};
tagNumObj = {'tagName':tagName};
data[i] = countObj;
data[i] = tagNumObj;

If the above is written like this
for (var i = 0; i < 7; i ) {

          
 var count = {$tagGroupArray[0]['count']};
 var tagName = "{$tagGroupArray[0]['tagName']}";
 countObj = {'count':count};
 tagNumObj = {'tagName':tagName};
 data[i] = countObj;
 data[i] = tagNumObj;

}

This is how it is displayed
var count = 8;
var tagName = "Hello";
countObj = {'count':count};
tagNumObj = {'tagName' :tagName};
data[i] = countObj;
data[i] = tagNumObj;

It means that i is not obtained, but how to get this i? Please answer. Or is there any other way to convert an ordinary array into a js array object? That’s fine. I’d like to ask sincerely

天蓬老师天蓬老师2751 days ago620

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-06-05 11:12:33

    Convert array to json format

    reply
    0
  • 高洛峰

    高洛峰2017-06-05 11:12:33

    If it is template assignment, use PHP to loop directly

    <for start="开始值" end="结束值" comparison="" step="步进值" name="循环变量名" >
    </for>

    If it is an interface to obtain the value, use json directly

    reply
    0
  • Cancelreply