vue 循环向数组里push进数据,视图没有更新

news/2024/7/19 14:05:36 标签: vue, javascript, js

如下代码,将myringList里的数据循环遍历出来,子元素Type=7的,就将这个元素push进movieList数组的data属性中,这种方法数据视图是不会更新的

this.myRingList.forEach(function(item){
    if(item.Type==7){
         this.movieList.data.push(item)
      }else{
         this.musicList.data.push(item)
     }
})

这时,可以创建两个变量movieListArr和musicListArr,将数据先push进变量中,然后再将变量赋值到data的movieList.data和musicList.data中

	let movieListArr=[]
    let musicListArr=[]
    this.myRingList.forEach(function(item){
        if(item.Type==7){
         movieListArr.push(item)
        }else{
          musicListArr.push(item)
    	 }
	 })
	this.movieList.data=movieListArr
	this.musicList.data=musicListArr

http://www.niftyadmin.cn/n/874923.html

相关文章

最长上升子序列_LintCode 题解丨字节跳动高频题:最长上升子序列

给定一个整数序列,找到最长上升子序列(LIS),返回LIS的长度。在线评测地址:LintCode 领扣​www.lintcode.com说明最长上升子序列的定义:最长上升子序列问题是在一个无序的给定序列中找到一个尽可能长的由低到…

js 电话号码脱敏,固话或移动号码或文字中夹杂的号码中间用*号替代

效果图 处理代码 98765432171 //导出一个 desensitization 方法 export function desensitization(strInfo){let reg /\d{7}/; //验证一个长度为7的整数let str strInfo; //将传入的包含电话号码的形参strInfo赋值给变量strlet str2 str.split().reverse().join() //数据…

微信小程序使用scroll-view 标签实现内容上下或左右滑动

scroll-view标签微信官方介绍 scroll-view标签属性 : scroll-x 为x轴(左右滑动),scroll-y为y轴(上下滑动) 左右滑动 scroll-view标签需要设置white-space: nowrap;里面的元素要设置为行内块元素 html <scroll-view scroll-x ><view class"templateitem" …

js 防抖和节流的方法

防抖 /** fun [function] 需要防抖的函数* delay [number] 毫秒&#xff0c;防抖期限值*/ function debounce(fun, delay 300) {let timer;return function () {let ctx thislet args argumentsif (timer) {clearTimeout(timer)}timer setTimeout(() > {timer nullfun…

报错 npm ERR! 404 Not Found - GET https://registry.npmjs.com/ - Not found

需要切换淘宝镜像 npm config set registry https://registry.npm.taobao.org

curl不通 k8s_curl 访问k8s api

下载jqchmod x jqmv jq /usr/bin/启用非安全端口kubectl proxy --port8080查看默认namespace pod列表curl localhost:8080/api/v1/namespaces/default/pods/ | jq -r .items[].metadata.nameHTTPS访问创建一个namespacekubectl create ns test创建rolekubectl create role pods…

草图大师怎么取消组件关联_sketchup取消隐藏(草图大师里取消全部隐藏快捷键)...

为什么SU中隐藏的组件&#xff0c;右键后怎么没有取消隐藏&#xff1f;...在sketchup菜单“窗口”里&#xff0c;有一个叫“资源目录”的窗口&#xff0c;里面可以看见模型里所有组件的嵌套关系&#xff0c;隐藏的组件以浅色显示你定义了组件&#xff0c;如果对其组件进行单独编…