dataTables对象数据的展现问题

datables处理带"."的数据做了一些特殊处理

前端JavaScript

columns: [
{data: "creator.name",title: "创建者", defaultContent: "", width: 120,align: "left"},
 {data: "creator.email",title: "创建者邮箱", defaultContent: "", width: 120, align: "left"},
{data: "creator.mobilePhoneNumber",title: "创建者手机", defaultContent: "", width: 120, align: "left"}
]

后台返回的数据格式必须为:

creator:{name: "张三", email: "[email protected]", mobilePhonoeNumber: "1333333333"}

datatables的源码在1274行,代码为

//else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 ||
		//	      mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1) )
		//{
		//	/* If there is a . in the source string then the data source is in a
		//	 * nested object so we loop over the data for each level to get the next
		//	 * level down. On each loop we test for undefined, and if found immediately
		//	 * return. This allows entire objects to be missing and sDefaultContent to
		//	 * be used if defined, rather than throwing an error
		//	 */
		//	var fetchData = function (data, type, src) {
		//		var arrayNotation, funcNotation, out, innerSrc;
        //
		//		if ( src !== "" )
		//		{
		//			var a = _fnSplitObjNotation( src );
        //
		//			for ( var i=0, iLen=a.length ; i<iLen ; i++ )
		//			{
		//				// Check if we are dealing with special notation
		//				arrayNotation = a[i].match(__reArray);
		//				funcNotation = a[i].match(__reFn);
        //
		//				if ( arrayNotation )
		//				{
		//					// Array notation
		//					a[i] = a[i].replace(__reArray, '');
        //
		//					// Condition allows simply [] to be passed in
		//					if ( a[i] !== "" ) {
		//						data = data[ a[i] ];
		//					}
		//					out = [];
        //
		//					// Get the remainder of the nested object to get
		//					a.splice( 0, i+1 );
		//					innerSrc = a.join('.');
        //
		//					// Traverse each entry in the array getting the properties requested
		//					if ( $.isArray( data ) ) {
		//						for ( var j=0, jLen=data.length ; j<jLen ; j++ ) {
		//							out.push( fetchData( data[j], type, innerSrc ) );
		//						}
		//					}
        //
		//					// If a string is given in between the array notation indicators, that
		//					// is used to join the strings together, otherwise an array is returned
		//					var join = arrayNotation[0].substring(1, arrayNotation[0].length-1);
		//					data = (join==="") ? out : out.join(join);
        //
		//					// The inner call to fetchData has already traversed through the remainder
		//					// of the source requested, so we exit from the loop
		//					break;
		//				}
		//				else if ( funcNotation )
		//				{
		//					// Function call
		//					a[i] = a[i].replace(__reFn, '');
		//					data = data[ a[i] ]();
		//					continue;
		//				}
        //
		//				if ( data === null || data[ a[i] ] === undefined )
		//				{
		//					return undefined;
		//				}
		//				data = data[ a[i] ];
		//			}
		//		}
        //
		//		return data;
		//	};
        //
		//	return function (data, type) { // row and meta also passed, but not used
		//		return fetchData( data, type, mSource );
		//	};
		//}

我的解决方案

返回的数据格式为:

{creator.name:"张三",creator.email:"[email protected]",creator.mobilePhonoeNumber:"1333333333"}

需要把dataTables的代码注释掉才能展示数据

相关推荐