示例#1
0
文件: object.go 项目: GarX/JsObject
func (this *JsObject) Append(value interface{}) {
	if !util.IsArray(this.value) {
		return
	}
	v := this.value.([]*JsObject)
	v = append(v, pack(value))
	this.value = v
}
示例#2
0
文件: object.go 项目: GarX/JsObject
func (this *JsObject) GetByIndex(index int) *JsObject {
	if !util.IsArray(this.value) {
		return nil
	}
	v := this.value.([]*JsObject)
	if l := len(v); l <= index {
		return nil
	}
	return v[index]
}
示例#3
0
文件: object.go 项目: GarX/JsObject
func (this *JsObject) Len() int {
	if util.IsArray(this.value) {
		v := this.value.([]*JsObject)
		return len(v)
	}
	if util.IsMap(this.value) {
		v := this.value.(map[interface{}]*JsObject)
		return len(v)
	}
	return 0
}
示例#4
0
文件: object.go 项目: GarX/JsObject
func (this *JsObject) SetByIndex(index int, value interface{}) {
	if !util.IsArray(this.value) {
		array := make([]*JsObject, index+1)
		array[index] = pack(value)
		this.value = array
		return
	} else {
		v := this.value.([]*JsObject)
		if l := len(v); l <= index {
			sliceToAppend := make([]*JsObject, index-l+1)
			this.value = append(v, sliceToAppend...)
			v = this.value.([]*JsObject)
		}
		v[index] = pack(value)
	}
}