dataset.js 변경된 파일 추가(addData 추가)

main
이범준 1 year ago
parent 372275d99d
commit af09daa58a

@ -450,6 +450,10 @@ class Dataset {
this._byKeys = {};
this._current = null;
let data = this._getDataItems(obj);
this._items = data.items;
this._byKeys = data.byKeys;
/*
obj = obj || {};
let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || [];
if (!Array.isArray(array))
@ -460,12 +464,62 @@ class Dataset {
let key = "key-" + this.getKey(item.data);
this._byKeys[key] = item;
});
*/
this.onDatasetChange(obj);
this.setState(!Array.isArray(obj) ? obj.state : state);
this.onDirtiesChange(this.dirty);
return this;
}
_getDataItems(obj) {
obj = obj || {};
let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || [];
if (!Array.isArray(array))
throw new Error("The data must be an array");
let _items = array.map(e => new DataItem(e, this._formats)),
_byKeys = {};
_items.forEach(item => {
let key = "key-" + this.getKey(item.data);
_byKeys[key] = item;
});
return {
items: _items,
byKeys: _byKeys
};
}
/**Adds user data to the Dataset.
* To get user data from an object, the dataGetter configured is called.
* After user data is set, the methods
* <ul> <li>{@link Dataset#onDatasetChange}</li>
* <li>{@link Dataset#onCurrentChange}</li>
* <li>{@link Dataset#onSelectionChange}</li>
* <li>{@link Dataset#onDirtiesChange}</li>
* </ul>
* are called back.
* @param {array|object} obj user data or an object that has user data
* @returns {Dataset} the Dataset
*/
addData(obj) {
if (this.empty)
return this.setData(obj);
let data = this._getDataItems(obj);
this._items = this._items.concat(data.items);
this._byKeys = {
...this._byKeys,
...data.byKeys
};
this.onDatasetChange(obj);
this.setState(!Array.isArray(obj) ? obj.state : state);
this.onDirtiesChange(this.dirty);
return this;
}
/**Clears the Dataset's user data.
@ -1140,6 +1194,7 @@ class DatasetControl {
this.prefix = conf.prefix;
this.prefixName = conf.prefixName;
this.infoSize = conf.infoSize;
this.appendData = conf.appendData;
this.query = {};
@ -1184,7 +1239,13 @@ class DatasetControl {
ajax.get({
url:this.urls.load,
data:this.query,
success:resp => this.setData(resp)
success:resp => {
if (!this.appendData || this.query.pageNum == 1)
this.setData(resp);
else {
this.addData(resp);
}
}
});
}
@ -1192,6 +1253,10 @@ class DatasetControl {
this.dataset.setData(obj);
}
addData(obj) {
this.dataset.addData(obj);
}
onDatasetChange(obj) {
debug("onDatasetChange", obj);
}

Loading…
Cancel
Save