收藏
回答

【基础问题】请问图中的程序是什么意思呢?

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

以下是程序内容:


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的截图:


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


谢谢。

最后一次编辑于  2019-02-13
回答关注问题邀请回答
收藏

3 个回答

  • 吴奕群
    吴奕群
    2019-02-13

    posts_content是对象啊

    2019-02-13
    有用 1
    回复
  • 2019-02-13

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

    2019-02-13
    有用
    回复
  • 拾忆
    拾忆
    2019-02-13

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

    2019-02-13
    有用
    回复 4
    • 2019-02-13

      是加上key就算是循环了吗?等于这个key是循环的关键字吗?

      2019-02-13
      回复
    • 拾忆
      拾忆
      2019-02-13回复

      对象不需要循环,取值 {{posts_content.date}} 就行

      2019-02-13
      回复
    • 拾忆
      拾忆
      2019-02-13回复

      看看基础吧:https://www.cnblogs.com/chenyablog/p/6477866.html

      2019-02-13
      回复
    • 2019-02-14回复拾忆

      嗯嗯,我基础差,谢谢指点~~~

      2019-02-14
      回复
登录 后发表内容