Skip to content

Commit

Permalink
fix: _method error
Browse files Browse the repository at this point in the history
  • Loading branch information
onvno committed Aug 16, 2016
1 parent e98b17a commit bb03148
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 391 deletions.
5 changes: 1 addition & 4 deletions js/dataTable/indexRow.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ import {


import { import {
formatValue, //需要最终产出, formatValue, //需要最终产出,
_findField,
_getField
} from './row-util'; } from './row-util';




Expand Down Expand Up @@ -139,8 +137,7 @@ class Row extends Events{


//util //util
this.formatValue= formatValue; this.formatValue= formatValue;
this._findField = _findField;
this._getField = _getField;


this.init(); this.init();
} }
Expand Down
146 changes: 73 additions & 73 deletions js/dataTable/removeRow.js
Original file line number Original file line Diff line number Diff line change
@@ -1,74 +1,74 @@
/** /**
* Module : kero dataTable removeRow * Module : kero dataTable removeRow
* Author : liuyk(liuyk@yonyou.com) * Author : liuyk(liuyk@yonyou.com)
* Date : 2016-08-01 14:34:01 * Date : 2016-08-01 14:34:01
*/ */
import {_formatToIndicesArray} from './util'; import {_formatToIndicesArray} from './util';


const removeRowByRowId = function (rowId) { const removeRowByRowId = function (rowId) {
var index = this.getIndexByRowId(rowId) var index = this.getIndexByRowId(rowId)
if (index != -1) if (index != -1)
this.removeRow(index) this.removeRow(index)
} }


const removeRow = function (index) { const removeRow = function (index) {
if (index instanceof Row) { if (index instanceof Row) {
index = this.getIndexByRowId(index.rowId) index = this.getIndexByRowId(index.rowId)
} }
this.removeRows([index]); this.removeRows([index]);
} }


const removeAllRows = function () { const removeAllRows = function () {
this.rows([]) this.rows([])
this.selectedIndices([]) this.selectedIndices([])
this.focusIndex(-1) this.focusIndex(-1)
this.trigger(DataTable.ON_DELETE_ALL) this.trigger(DataTable.ON_DELETE_ALL)
this.updateCurrIndex(); this.updateCurrIndex();
} }


const removeRows = function (indices) { const removeRows = function (indices) {
indices = _formatToIndicesArray(indices) indices = _formatToIndicesArray(this, indices)
indices = indices.sort() indices = indices.sort()
var rowIds = [], rows = this.rows(), deleteRows = []; var rowIds = [], rows = this.rows(), deleteRows = [];
for (var i = indices.length - 1; i >= 0; i--) { for (var i = indices.length - 1; i >= 0; i--) {
var index = indices[i] var index = indices[i]
var delRow = rows[index]; var delRow = rows[index];
if (delRow == null) { if (delRow == null) {
continue; continue;
} }
rowIds.push(delRow.rowId) rowIds.push(delRow.rowId)
var deleteRow = rows.splice(index, 1); var deleteRow = rows.splice(index, 1);
deleteRows.push(deleteRow[0]); deleteRows.push(deleteRow[0]);
this.updateSelectedIndices(index, '-') this.updateSelectedIndices(index, '-')
this.updateFocusIndex(index, '-') this.updateFocusIndex(index, '-')
} }
this.rows(rows) this.rows(rows)
this.deleteRows = deleteRows; this.deleteRows = deleteRows;
this.trigger(DataTable.ON_DELETE, { this.trigger(DataTable.ON_DELETE, {
indices: indices, indices: indices,
rowIds: rowIds, rowIds: rowIds,
deleteRows: deleteRows deleteRows: deleteRows
}) })
this.updateCurrIndex(); this.updateCurrIndex();
} }




/** /**
* 清空datatable的所有数据以及分页数据以及index * 清空datatable的所有数据以及分页数据以及index
*/ */
const clear = function () { const clear = function () {
this.removeAllRows(); this.removeAllRows();
this.cachedPages = []; this.cachedPages = [];
this.totalPages(1); this.totalPages(1);
this.pageIndex(0); this.pageIndex(0);
this.focusIndex(-1); this.focusIndex(-1);
this.selectedIndices([]); this.selectedIndices([]);
} }


export { export {
removeRowByRowId, removeRowByRowId,
removeRow, removeRow,
removeAllRows, removeAllRows,
removeRows, removeRows,
clear clear
} }
30 changes: 15 additions & 15 deletions js/dataTable/row-data.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const setValue = function (fieldName, value, ctx, options) {
oldValue = '' oldValue = ''
if (eq(oldValue, value)) return; if (eq(oldValue, value)) return;
_getField(this, fieldName)['value'] = value; _getField(this, fieldName)['value'] = value;
_triggerChange(fieldName, oldValue, ctx); _triggerChange(this, fieldName, oldValue, ctx);
} }


const setChildValue = function(fieldName, value){ const setChildValue = function(fieldName, value){
Expand Down Expand Up @@ -77,19 +77,19 @@ const setChildSimpleDataByRowId = function(rowId, data){
* @param {[type]} subscribe * @param {[type]} subscribe
* @param {[type]} parentKey [父项key,数据项为数组时获取meta值用] * @param {[type]} parentKey [父项key,数据项为数组时获取meta值用]
*/ */
const _setData = function(sourceData, targetData, subscribe, parentKey){ const _setData = function(rowObj, sourceData, targetData, subscribe, parentKey){
for (var key in sourceData) { for (var key in sourceData) {
var _parentKey = parentKey || null; var _parentKey = parentKey || null;
//if (targetData[key]) { //if (targetData[key]) {
targetData[key] = targetData[key] || {}; targetData[key] = targetData[key] || {};
var valueObj = sourceData[key] var valueObj = sourceData[key]
if (typeof valueObj != 'object') if (typeof valueObj != 'object')
this.parent.createField(key); rowObj.parent.createField(key);
//if (typeof this.parent.meta[key] === 'undefined') continue; //if (typeof this.parent.meta[key] === 'undefined') continue;
if (valueObj == null || typeof valueObj != 'object'){ if (valueObj == null || typeof valueObj != 'object'){
targetData[key]['value'] = this.formatValue(key, valueObj) targetData[key]['value'] = rowObj.formatValue(key, valueObj)
if (subscribe === true && (oldValue !== targetData[key]['value'])){ if (subscribe === true && (oldValue !== targetData[key]['value'])){
_triggerChange(key, oldValue); _triggerChange(rowObj, key, oldValue);
} }
} }
else { else {
Expand All @@ -100,26 +100,26 @@ const _setData = function(sourceData, targetData, subscribe, parentKey){
alert(valueObj.error); alert(valueObj.error);
} else if (valueObj.value || valueObj.value === null || valueObj.meta || valueObj.value === '' || valueObj.value === '0' || valueObj.value === 0){ } else if (valueObj.value || valueObj.value === null || valueObj.meta || valueObj.value === '' || valueObj.value === '0' || valueObj.value === 0){
var oldValue = targetData[key]['value']; var oldValue = targetData[key]['value'];
targetData[key]['value'] = this.formatValue(key, valueObj.value) targetData[key]['value'] = rowObj.formatValue(key, valueObj.value)
if (subscribe === true && (oldValue !== targetData[key]['value'])){ if (subscribe === true && (oldValue !== targetData[key]['value'])){
_triggerChange(key, oldValue); _triggerChange(rowObj, key, oldValue);
} }
for (var k in valueObj.meta) { for (var k in valueObj.meta) {
this.setMeta(key, k, valueObj.meta[k]) rowObj.setMeta(key, k, valueObj.meta[k])
} }
}else if (isArray(valueObj)){ }else if (isArray(valueObj)){
targetData[key].isChild = true; targetData[key].isChild = true;
//ns 是多级数据时的空间名: 最顶层的dataTable没有ns。 f1.f2.f3 //ns 是多级数据时的空间名: 最顶层的dataTable没有ns。 f1.f2.f3
var _key = _parentKey == null ? key : _parentKey + '.' + key; var _key = _parentKey == null ? key : _parentKey + '.' + key;
var ns = this.parent.ns === '' ? key : this.parent.ns + '.' + _key var ns = rowObj.parent.ns === '' ? key : rowObj.parent.ns + '.' + _key
if(this.parent.meta[_key]){ if(rowObj.parent.meta[_key]){
var meta = this.parent.meta[_key]['meta'] var meta = rowObj.parent.meta[_key]['meta']
targetData[key].value = new u.DataTable({root:this.parent.root,ns:ns,meta:meta}); targetData[key].value = new u.DataTable({root:rowObj.parent.root,ns:ns,meta:meta});
targetData[key].value.setSimpleData(valueObj); targetData[key].value.setSimpleData(valueObj);
} }
}else{ }else{
_parentKey = _parentKey == null ? key : _parentKey + '.' + key; _parentKey = _parentKey == null ? key : _parentKey + '.' + key;
this._setData(valueObj, targetData[key], null, _parentKey); _setData(rowObj, valueObj, targetData[key], null, _parentKey);
} }
} }
//} //}
Expand All @@ -136,7 +136,7 @@ const setData = function (data, subscribe) {
var sourceData = data.data, var sourceData = data.data,
targetData = this.data; targetData = this.data;
if (this.parent.root.strict != true){ if (this.parent.root.strict != true){
this._setData(sourceData, targetData,subscribe); _setData(this, sourceData, targetData,subscribe);
return; return;
} }


Expand Down Expand Up @@ -191,7 +191,7 @@ const setData = function (data, subscribe) {
} }
} }
if (subscribe === true && (oldValue !== newValue)){ if (subscribe === true && (oldValue !== newValue)){
_triggerChange(key, oldValue); _triggerChange(this, key, oldValue);
} }


} }
Expand Down
8 changes: 4 additions & 4 deletions js/dataTable/row-getSimpleData.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import {_dateToUTCString} from './row-util'; import {_dateToUTCString} from './row-util';
import {isEmptyObject} from 'neoui-sparrow/js/util'; import {isEmptyObject} from 'neoui-sparrow/js/util';


const _getSimpleData = function(data){ const _getSimpleData = function(rowObj, data){
var _data = {}; var _data = {};
var meta = this.parent.getMeta() || {}; var meta = rowObj.parent.getMeta() || {};
for(var key in data){ for(var key in data){
if (key === 'meta' || isEmptyObject(data[key])){ if (key === 'meta' || isEmptyObject(data[key])){
continue; continue;
Expand All @@ -31,7 +31,7 @@ const _getSimpleData = function(data){
} }
} }
else{ else{
_data[key] = this._getSimpleData(data[key]) _data[key] = _getSimpleData(rowObj, data[key])
} }
} }
return _data; return _data;
Expand All @@ -43,7 +43,7 @@ const getSimpleData = function(options){
var fields = options['fields'] || null; var fields = options['fields'] || null;
var meta = this.parent.getMeta(); var meta = this.parent.getMeta();
var data = this.data; var data = this.data;
var _data = this._getSimpleData(data); //{}; var _data = _getSimpleData(this, data); //{};
var _fieldsData = {}; var _fieldsData = {};
if (fields){ if (fields){
for (var key in _data){ for (var key in _data){
Expand Down
34 changes: 17 additions & 17 deletions js/dataTable/row-util.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,32 +50,32 @@ const _dateToUTCString = function (date) {


const _triggerChange = function(rowObj,fieldName, oldValue, ctx){ const _triggerChange = function(rowObj,fieldName, oldValue, ctx){
_getField(rowObj, fieldName).changed = true _getField(rowObj, fieldName).changed = true
if (this.status != Row.STATUS.NEW) if (rowObj.status != Row.STATUS.NEW)
this.status = Row.STATUS.UPDATE rowObj.status = Row.STATUS.UPDATE
if (this.valueChange[fieldName]) if (rowObj.valueChange[fieldName])
this.valueChange[fieldName](-this.valueChange[fieldName]()) rowObj.valueChange[fieldName](-rowObj.valueChange[fieldName]())
if (this.parent.getCurrentRow() == this && this.parent.valueChange[fieldName]){ if (rowObj.parent.getCurrentRow() == rowObj && rowObj.parent.valueChange[fieldName]){
this.parent.valueChange[fieldName](-this.parent.valueChange[fieldName]()); rowObj.parent.valueChange[fieldName](-rowObj.parent.valueChange[fieldName]());
} }
if (this.parent.ns){ if (rowObj.parent.ns){
var fName = this.parent.ns + '.' + fieldName; var fName = rowObj.parent.ns + '.' + fieldName;
if (this.parent.root.valueChange[fName]) if (rowObj.parent.root.valueChange[fName])
this.parent.root.valueChange[fName](-this.parent.root.valueChange[fName]()); rowObj.parent.root.valueChange[fName](-rowObj.parent.root.valueChange[fName]());
} }


var event = { var event = {
eventType: 'dataTableEvent', eventType: 'dataTableEvent',
dataTable: this.parent.id, dataTable: rowObj.parent.id,
rowId: this.rowId, rowId: rowObj.rowId,
field: fieldName, field: fieldName,
oldValue: oldValue, oldValue: oldValue,
newValue: this.getValue(fieldName), newValue: rowObj.getValue(fieldName),
ctx: ctx || "" ctx: ctx || ""
} }
this.parent.trigger(DataTable.ON_VALUE_CHANGE, event); rowObj.parent.trigger(DataTable.ON_VALUE_CHANGE, event);
this.parent.trigger(fieldName + "." + DataTable.ON_VALUE_CHANGE, event); rowObj.parent.trigger(fieldName + "." + DataTable.ON_VALUE_CHANGE, event);
if (this == this.parent.getCurrentRow()) if (rowObj == rowObj.parent.getCurrentRow())
this.parent.trigger(fieldName + "." + DataTable.ON_CURRENT_VALUE_CHANGE, event); rowObj.parent.trigger(fieldName + "." + DataTable.ON_CURRENT_VALUE_CHANGE, event);


}; };


Expand Down
Loading

0 comments on commit bb03148

Please sign in to comment.