Exemplo n.º 1
0
func (this *JsObject) Append(value interface{}) {
	if !util.IsArray(this.value) {
		return
	}
	v := this.value.([]*JsObject)
	v = append(v, pack(value))
	this.value = v
}
Exemplo n.º 2
0
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]
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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)
	}
}