Javascript Vue.js-将道具传递到$.each()(已装入)
安装组件时,我需要迭代对象文字。但是我很难使用Javascript Vue.js-将道具传递到$.each()(已装入),javascript,jquery,vue.js,each,Javascript,Jquery,Vue.js,Each,安装组件时,我需要迭代对象文字。但是我很难使用.each()函数中的道具数据。在each()函数中,当我使用console.log检查时,道具数据是“未定义的”。我的代码如下所示: [..] props: { active_categories: String, // example: "0,1,2,4", might also be NULL category_list: Array // example: [ 0:{ID
.each()
函数中的道具数据。在each()
函数中,当我使用console.log检查时,道具数据是“未定义的”。我的代码如下所示:
[..]
props: {
active_categories: String, // example: "0,1,2,4", might also be NULL
category_list: Array // example: [ 0:{ID:0, Status:0}, 1:{ID:1, Status:0} [..] ]
},
mounted: function(){
// iterate through the prop array 'category_list'
// if an ID of this array is included in the string 'active_categories',
// set 'Status=1'
$.each(this.category_list, function(key, value, active_categories) {
if(active_categories){
if(active_categories.includes(value.ID)){
value.Status = 1;
}
}
});
如何在.each()
函数中引入prop值?将此
赋值给名为self
的全局变量,然后在$中使用它。每个回调都是因为该回调中的此
具有不同的上下文:
mounted: function(){
let self=this
$.each(this.category_list, function(key, value) {
if(self.active_categories){
if(self.active_categories.includes(value.ID)){
value.Status = 1;
}
}
});