提交 289db036 编写于 作者: D dolymood

fix issue #163 , array findIndex

上级 c288db8c
function findIndex(ary, fn) {
if (ary.findIndex) {
return ary.findIndex(fn)
}
let index = -1
ary.some(function (item, i, ary) {
const ret = fn.call(this, item, i, ary)
if (ret) {
index = i
return ret
}
})
return index
}
function deepAssign(to, from) {
for (let key in from) {
if (!to[key] || typeof to[key] !== 'object') {
......@@ -65,4 +80,4 @@ function resetTypeValue(obj, key, defVal) {
}
}
export { deepAssign, createAddAPI, toLocaleDateString, resetTypeValue }
export { findIndex, deepAssign, createAddAPI, toLocaleDateString, resetTypeValue }
......@@ -17,7 +17,7 @@
<script>
import apiMixin from '../../common/mixins/api'
import pickerMixin from '../../common/mixins/picker'
import { deepAssign } from '../../common/helpers/util'
import { deepAssign, findIndex } from '../../common/helpers/util'
import { computeNatureMaxDay, formatType } from '../../common/lang/date'
const COMPONENT_NAME = 'cube-date-picker'
......@@ -145,13 +145,13 @@
selectedIndex() {
let selectedIndex = []
let data = this.data
let findIndex
let index
for (let i = 0; i < this.columnCount && i < 6 - this.startIndex; i++) {
findIndex = data.findIndex((item) => {
index = findIndex(data, (item) => {
return this.valueArray[i] && item.value === this.valueArray[i]
})
selectedIndex[i] = findIndex !== -1 ? findIndex : 0
selectedIndex[i] = index !== -1 ? index : 0
data = data[selectedIndex[i]].children
}
......
......@@ -7,6 +7,7 @@
</template>
<script>
import { findIndex } from '../../common/helpers/util'
const COMPONENT_NAME = 'cube-select'
const EVENT_CHANGE = 'change'
......@@ -67,23 +68,23 @@
return item
})]
},
findIndex() {
const findIndex = this.adaptOptions[0].findIndex((item) => {
valueIndex() {
const index = findIndex(this.adaptOptions[0], (item) => {
return item.value === this.value
})
this.picker && this.picker.setData(this.adaptOptions, findIndex !== -1 ? [findIndex] : [0])
this.picker && this.picker.setData(this.adaptOptions, index !== -1 ? [index] : [0])
return findIndex
return index
},
selectedText() {
return this.findIndex !== -1 ? this.adaptOptions[0][this.findIndex].text : ''
return this.valueIndex !== -1 ? this.adaptOptions[0][this.valueIndex].text : ''
}
},
created() {
this.picker = this.$createPicker({
title: this.title,
data: this.adaptOptions,
selectedIndex: this.findIndex !== -1 ? [this.findIndex] : [0],
selectedIndex: this.valueIndex !== -1 ? [this.valueIndex] : [0],
cancelTxt: this.cancelTxt,
confirmTxt: this.confirmTxt,
onSelect: this.hided,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册