How to loop assignment in thinkphp in js
天蓬老师
天蓬老师 2017-06-05 11:10:33
0
2
616

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
滿天的星座

Convert array to json format

小葫芦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template