问题描述
如题:我想实现如下要求:{name:'name2', rowNum:this.items.length, firstRowData:{address:'group2', tel:'1'},items:[{address:'group2', tel:'2'},{address:'group2', tel:'3'},{address:'group2', tel:'4'}]},我想让rowNum的值为 items数组的元素个数。请问怎么实现!!我上面这样的方式,会包this.items不存在错误!! 问题补充:xxzjlgo 写道
解决方案
var fn={name:'name2',rowNum:function(){ return this.items.length}firstRowData:{address:'group2', tel:'1'},items:[{address:'group2', tel:'2'},{address:'group2', tel:'3'},{address:'group2', tel:'4'}]}这样可以获取,刚那个错了
解决方案二:
直接量不存在this 一说var fn={name:'name2',rowNum:fn.items.length,firstRowData:{address:'group2', tel:'1'},items:[{address:'group2', tel:'2'},{address:'group2', tel:'3'},{address:'group2', tel:'4'}]},
时间: 2024-11-03 17:07:11