setData, addData, onDatasetChange 수정

master
mjkhan21 4 months ago
parent a4725ea23b
commit f8023f61db

@ -485,9 +485,10 @@ class Dataset {
* </ul>
* are called back.
* @param {array|object} obj user data or an object that has user data
* @param {object} obj optional information
* @returns {Dataset} the Dataset
*/
setData(obj) {
setData(obj, option) {
this._byKeys = {};
this._current = null;
@ -508,7 +509,7 @@ class Dataset {
this._byKeys[key] = item;
});
*/
this.onDatasetChange(obj);
this.onDatasetChange(obj, option);
this.setState(obj.state);
this.onDirtiesChange(this.dirty);
@ -544,9 +545,10 @@ class Dataset {
* </ul>
* are called back.
* @param {array|object} obj user data or an object that has user data
* @param {object} obj optional information
* @returns {Dataset} the Dataset
*/
addData(obj) {
addData(obj, option) {
if (this.empty)
return this.setData(obj);
@ -560,7 +562,7 @@ class Dataset {
obj = obj || {}
this.onDatasetChange(obj);
this.onDatasetChange(obj, option);
this.setState(!Array.isArray(obj) ? obj.state : state);
this.onDirtiesChange(this.dirty);
@ -1203,8 +1205,9 @@ class Dataset {
/**Called back when user data are set.
* @param {object|array} obj object that has user data or an array of user data
* @param {object} obj optional information
*/
onDatasetChange(obj) {this.log("Dataset changed", obj);}
onDatasetChange(obj, option) {this.log("Dataset changed", obj, "option", option);}
/**Called back when current user data is changed.
* @param {DataItem} currentItem current dataItem
@ -1258,7 +1261,7 @@ class DatasetControl {
this.query = {};
conf.onDatasetChange = obj => this.onDatasetChange(obj);
conf.onDatasetChange = (obj, option) => this.onDatasetChange(obj, option);
conf.onCurrentChange = item => this.onCurrentChange(item);
conf.onSelectionChange = selected => this.onSelectionChange(selected);
conf.onAppend = items => this.onAppend(items);
@ -1297,43 +1300,49 @@ class DatasetControl {
this._load();
}
_load(state, prev, callback) {
_load(option) {
option = option || {};
if (!this.query.pageNum)
this.query.pageNum = 1;
if (prev)
if (option.prev)
this.query.pageNum = Math.max(1, this.query.pageNum - 1);
ajax.get({
url:this.urls.load,
data:this.query,
success:resp => {
if (!prev)
resp.state = state;
if (!option.prev)
resp.state = option.state;
if (!this.appendData || this.query.pageNum == 1)
this.setData(resp);
this.setData(resp, option);
else {
this.addData(resp);
this.addData(resp, option);
}
if (callback)
callback();
if (option.callback)
option.callback();
}
});
}
reload(option) {
let all = option ? option.all : false,
prev = option ? option.prev : false,
if (!option)
option = {};
option.reloaded = true;
let all = option.all,
prev = option.prev,
state = this.dataset.state;
option.state = state;
if (!all) {
this._load(state, prev);
this._load(option);
} else {
let query = Object.assign({}, this.query),
state = this.dataset.state;
let query = Object.assign({}, this.query);
this.query.fetchSize = this.dataset.length;
this.query.pageNum = 1;
this.dataset.clear();
this._load(state, prev, () => {this.query = query;});
option.callback = () => {this.query = query;};
this._load(option);
}
}
@ -1344,16 +1353,16 @@ class DatasetControl {
document.location.href = this.urls.load + "?" + query;
}
setData(obj) {
this.dataset.setData(obj);
setData(obj, option) {
this.dataset.setData(obj, option);
}
addData(obj) {
this.dataset.addData(obj);
addData(obj, option) {
this.dataset.addData(obj, option);
}
onDatasetChange(obj) {
debug("onDatasetChange", obj);
onDatasetChange(obj, option) {
debug("onDatasetChange", obj, option);
}
getCurrent(option) {

Loading…
Cancel
Save