Permalink
Browse files

fix: _method error

  • Loading branch information...
onvno committed Aug 16, 2016
1 parent e98b17a commit bb031481ec1fc3217a3e7b8711bbaddd8a71c7d2
View
@@ -60,8 +60,6 @@ import {
import {
formatValue, //需要最终产出,
_findField,
_getField
} from './row-util';
@@ -139,8 +137,7 @@ class Row extends Events{
//util
this.formatValue= formatValue;
this._findField = _findField;
this._getField = _getField;
this.init();
}
View
@@ -1,74 +1,74 @@
/**
* Module : kero dataTable removeRow
* Author : liuyk(liuyk@yonyou.com)
* Date : 2016-08-01 14:34:01
*/
import {_formatToIndicesArray} from './util';
const removeRowByRowId = function (rowId) {
var index = this.getIndexByRowId(rowId)
if (index != -1)
this.removeRow(index)
}
const removeRow = function (index) {
if (index instanceof Row) {
index = this.getIndexByRowId(index.rowId)
}
this.removeRows([index]);
}
const removeAllRows = function () {
this.rows([])
this.selectedIndices([])
this.focusIndex(-1)
this.trigger(DataTable.ON_DELETE_ALL)
this.updateCurrIndex();
}
const removeRows = function (indices) {
indices = _formatToIndicesArray(indices)
indices = indices.sort()
var rowIds = [], rows = this.rows(), deleteRows = [];
for (var i = indices.length - 1; i >= 0; i--) {
var index = indices[i]
var delRow = rows[index];
if (delRow == null) {
continue;
}
rowIds.push(delRow.rowId)
var deleteRow = rows.splice(index, 1);
deleteRows.push(deleteRow[0]);
this.updateSelectedIndices(index, '-')
this.updateFocusIndex(index, '-')
}
this.rows(rows)
this.deleteRows = deleteRows;
this.trigger(DataTable.ON_DELETE, {
indices: indices,
rowIds: rowIds,
deleteRows: deleteRows
})
this.updateCurrIndex();
}
/**
* 清空datatable的所有数据以及分页数据以及index
*/
const clear = function () {
this.removeAllRows();
this.cachedPages = [];
this.totalPages(1);
this.pageIndex(0);
this.focusIndex(-1);
this.selectedIndices([]);
}
export {
removeRowByRowId,
removeRow,
removeAllRows,
removeRows,
clear
/**
* Module : kero dataTable removeRow
* Author : liuyk(liuyk@yonyou.com)
* Date : 2016-08-01 14:34:01
*/
import {_formatToIndicesArray} from './util';
const removeRowByRowId = function (rowId) {
var index = this.getIndexByRowId(rowId)
if (index != -1)
this.removeRow(index)
}
const removeRow = function (index) {
if (index instanceof Row) {
index = this.getIndexByRowId(index.rowId)
}
this.removeRows([index]);
}
const removeAllRows = function () {
this.rows([])
this.selectedIndices([])
this.focusIndex(-1)
this.trigger(DataTable.ON_DELETE_ALL)
this.updateCurrIndex();
}
const removeRows = function (indices) {
indices = _formatToIndicesArray(this, indices)
indices = indices.sort()
var rowIds = [], rows = this.rows(), deleteRows = [];
for (var i = indices.length - 1; i >= 0; i--) {
var index = indices[i]
var delRow = rows[index];
if (delRow == null) {
continue;
}
rowIds.push(delRow.rowId)
var deleteRow = rows.splice(index, 1);
deleteRows.push(deleteRow[0]);
this.updateSelectedIndices(index, '-')
this.updateFocusIndex(index, '-')
}
this.rows(rows)
this.deleteRows = deleteRows;
this.trigger(DataTable.ON_DELETE, {
indices: indices,
rowIds: rowIds,
deleteRows: deleteRows
})
this.updateCurrIndex();
}
/**
* 清空datatable的所有数据以及分页数据以及index
*/
const clear = function () {
this.removeAllRows();
this.cachedPages = [];
this.totalPages(1);
this.pageIndex(0);
this.focusIndex(-1);
this.selectedIndices([]);
}
export {
removeRowByRowId,
removeRow,
removeAllRows,
removeRows,
clear
}
View
@@ -18,7 +18,7 @@ const setValue = function (fieldName, value, ctx, options) {
oldValue = ''
if (eq(oldValue, value)) return;
_getField(this, fieldName)['value'] = value;
_triggerChange(fieldName, oldValue, ctx);
_triggerChange(this, fieldName, oldValue, ctx);
}
const setChildValue = function(fieldName, value){
@@ -77,19 +77,19 @@ const setChildSimpleDataByRowId = function(rowId, data){
* @param {[type]} subscribe
* @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) {
var _parentKey = parentKey || null;
//if (targetData[key]) {
targetData[key] = targetData[key] || {};
var valueObj = sourceData[key]
if (typeof valueObj != 'object')
this.parent.createField(key);
rowObj.parent.createField(key);
//if (typeof this.parent.meta[key] === 'undefined') continue;
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'])){
_triggerChange(key, oldValue);
_triggerChange(rowObj, key, oldValue);
}
}
else {
@@ -100,26 +100,26 @@ const _setData = function(sourceData, targetData, subscribe, parentKey){
alert(valueObj.error);
} else if (valueObj.value || valueObj.value === null || valueObj.meta || valueObj.value === '' || valueObj.value === '0' || valueObj.value === 0){
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'])){
_triggerChange(key, oldValue);
_triggerChange(rowObj, key, oldValue);
}
for (var k in valueObj.meta) {
this.setMeta(key, k, valueObj.meta[k])
rowObj.setMeta(key, k, valueObj.meta[k])
}
}else if (isArray(valueObj)){
targetData[key].isChild = true;
//ns 是多级数据时的空间名: 最顶层的dataTable没有ns。 f1.f2.f3
var _key = _parentKey == null ? key : _parentKey + '.' + key;
var ns = this.parent.ns === '' ? key : this.parent.ns + '.' + _key
if(this.parent.meta[_key]){
var meta = this.parent.meta[_key]['meta']
targetData[key].value = new u.DataTable({root:this.parent.root,ns:ns,meta:meta});
var ns = rowObj.parent.ns === '' ? key : rowObj.parent.ns + '.' + _key
if(rowObj.parent.meta[_key]){
var meta = rowObj.parent.meta[_key]['meta']
targetData[key].value = new u.DataTable({root:rowObj.parent.root,ns:ns,meta:meta});
targetData[key].value.setSimpleData(valueObj);
}
}else{
_parentKey = _parentKey == null ? key : _parentKey + '.' + key;
this._setData(valueObj, targetData[key], null, _parentKey);
_setData(rowObj, valueObj, targetData[key], null, _parentKey);
}
}
//}
@@ -136,7 +136,7 @@ const setData = function (data, subscribe) {
var sourceData = data.data,
targetData = this.data;
if (this.parent.root.strict != true){
this._setData(sourceData, targetData,subscribe);
_setData(this, sourceData, targetData,subscribe);
return;
}
@@ -191,7 +191,7 @@ const setData = function (data, subscribe) {
}
}
if (subscribe === true && (oldValue !== newValue)){
_triggerChange(key, oldValue);
_triggerChange(this, key, oldValue);
}
}
@@ -6,9 +6,9 @@
import {_dateToUTCString} from './row-util';
import {isEmptyObject} from 'neoui-sparrow/js/util';
const _getSimpleData = function(data){
const _getSimpleData = function(rowObj, data){
var _data = {};
var meta = this.parent.getMeta() || {};
var meta = rowObj.parent.getMeta() || {};
for(var key in data){
if (key === 'meta' || isEmptyObject(data[key])){
continue;
@@ -31,7 +31,7 @@ const _getSimpleData = function(data){
}
}
else{
_data[key] = this._getSimpleData(data[key])
_data[key] = _getSimpleData(rowObj, data[key])
}
}
return _data;
@@ -43,7 +43,7 @@ const getSimpleData = function(options){
var fields = options['fields'] || null;
var meta = this.parent.getMeta();
var data = this.data;
var _data = this._getSimpleData(data); //{};
var _data = _getSimpleData(this, data); //{};
var _fieldsData = {};
if (fields){
for (var key in _data){
View
@@ -50,32 +50,32 @@ const _dateToUTCString = function (date) {
const _triggerChange = function(rowObj,fieldName, oldValue, ctx){
_getField(rowObj, fieldName).changed = true
if (this.status != Row.STATUS.NEW)
this.status = Row.STATUS.UPDATE
if (this.valueChange[fieldName])
this.valueChange[fieldName](-this.valueChange[fieldName]())
if (this.parent.getCurrentRow() == this && this.parent.valueChange[fieldName]){
this.parent.valueChange[fieldName](-this.parent.valueChange[fieldName]());
if (rowObj.status != Row.STATUS.NEW)
rowObj.status = Row.STATUS.UPDATE
if (rowObj.valueChange[fieldName])
rowObj.valueChange[fieldName](-rowObj.valueChange[fieldName]())
if (rowObj.parent.getCurrentRow() == rowObj && rowObj.parent.valueChange[fieldName]){
rowObj.parent.valueChange[fieldName](-rowObj.parent.valueChange[fieldName]());
}
if (this.parent.ns){
var fName = this.parent.ns + '.' + fieldName;
if (this.parent.root.valueChange[fName])
this.parent.root.valueChange[fName](-this.parent.root.valueChange[fName]());
if (rowObj.parent.ns){
var fName = rowObj.parent.ns + '.' + fieldName;
if (rowObj.parent.root.valueChange[fName])
rowObj.parent.root.valueChange[fName](-rowObj.parent.root.valueChange[fName]());
}
var event = {
eventType: 'dataTableEvent',
dataTable: this.parent.id,
rowId: this.rowId,
dataTable: rowObj.parent.id,
rowId: rowObj.rowId,
field: fieldName,
oldValue: oldValue,
newValue: this.getValue(fieldName),
newValue: rowObj.getValue(fieldName),
ctx: ctx || ""
}
this.parent.trigger(DataTable.ON_VALUE_CHANGE, event);
this.parent.trigger(fieldName + "." + DataTable.ON_VALUE_CHANGE, event);
if (this == this.parent.getCurrentRow())
this.parent.trigger(fieldName + "." + DataTable.ON_CURRENT_VALUE_CHANGE, event);
rowObj.parent.trigger(DataTable.ON_VALUE_CHANGE, event);
rowObj.parent.trigger(fieldName + "." + DataTable.ON_VALUE_CHANGE, event);
if (rowObj == rowObj.parent.getCurrentRow())
rowObj.parent.trigger(fieldName + "." + DataTable.ON_CURRENT_VALUE_CHANGE, event);
};
Oops, something went wrong.

0 comments on commit bb03148

Please sign in to comment.