【基础问题】请问图中的程序是什么意思呢?
发布于 6 年前 作者 gulei 11936 次浏览 来自 问答

大家好,我是小程序初学者,跟着老师的视频在学习,但是还是遇到了不明白的地方,希望得到大家的指点,谢谢。

以下是程序内容:

1.这是.js文件中的内容:

onLoad: function (options) {

var posts_content=[

{

date: “2019-02-14”,

title: “天津为明国际文化节”,

post_img: “/images/xinwentu/xinwentu1.jpg”,

content: “国际文化节简介,后边为补充文字扩扩扩”,

view_num: “22”,

collect_num: “196”,

author_img: “/images/head image/xiaohui.png”,

},

……

this.setData({

posts_key:posts_content})

2.这是.wxml中的内容:

<block wx:for="{{posts_key}}" wx:for-item=“item”>

<view class=‘post-container’>

<view class=‘post-author-date’>

<image class=“post-author” src="{{item.author_img}}"></image>

……

请教大家,

this.setData({

posts_key:posts_content})

这个是什么意思呢?是必须这样写吗?为什么我直接在wx:for后边加上posts_content不行呢?

这是直接添加posts_content的截图:

而且总是有黄色的这个报警,也不知道是什么意思?从网上查了,说是可以忽略。

谢谢。

3 回复

等于posts_content只是变量,不能直接循环,需要把值赋给key这个关键字后才可以循环是吧?

posts_content是对象啊

posts_content是对象,又不是数组,哪里来的循环?

回到顶部