fordth / jinqJs

jinqJs provides a simple way to perform SQL like queries on javaScript arrays, collections and web services using LINQ expressions.
Other
93 stars 29 forks source link

Are those two fields need to transfer the position? rItem and lItem. jinqjs line544 #31

Open Jackclarify opened 6 years ago

Jackclarify commented 6 years ago

https://github.com/fordth/jinqJs/blob/4fc27afe17184961ec43616d0740056ea4043e8e/jinqjs.js#L544 Are those two fields need to transfer the places? rItem and lItem. Here is a simple example

let items = [ { 'id': '8936b02f-e18c-4627-96e2-c61a568d98ac',
    'response': '' }];
let answers = [{"comment":"0000","id":"8936b02f-e18c-4627-96e2-c61a568d98ac","value":0}];
let ddd = new jinq().from(items).leftJoin(answers).on('id').select(question => {
                return {
                    id: question.id,
                    response: question.value,
                    comment: question.comment,
                    responseTime: question.currentTime
                };
            });

console.dir(ddd);
// [ { id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
//     response: 0,
//     comment: '0000',
//     responseTime: undefined } ]

let items2 = [ { 'id': '8936b02f-e18c-4627-96e2-c61a568d98ac',
    'response': '',
    'comment': '3333' }];
let ddd2 = new jinq().from(items2).leftJoin(answers).on('id').select(question => {
                return {
                    id: question.id,
                    response: question.value,
                    comment: question.comment,
                    responseTime: question.currentTime
                };
            });

console.dir(ddd2);
// [ { id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
//     response: 0,
//     comment: '3333',   //  <== here not changed
//     responseTime: undefined } ]

// expect result: 
// [ { id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
//     response: 0,
//     comment: '0000',   //  <== expect change here
//     responseTime: undefined } ]

mergeObjectsFields method details:

        mergeObjectsFields = function (objects) {
            var obj = {};

            for (var index = 0; index < objects.length; index++) {
                for (var prop in objects[index]) {
                    obj[prop] = objects[index][prop];
                }
            }
            console.dir(obj);
            console.dir('_______________  finally _________________________');
            return obj;
        },

item change process: rItem:

{ comment: '0000',
  id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
  value: 0 }

lItem: { id: '8936b02f-e18c-4627-96e2-c61a568d98ac', response: '' } mergeObjectsFields([rItem, lItem]): // <== line 544;

{ comment: '0000', // <== mergeObjectsFields method response
  id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
  value: 0,
  response: '' }

item2 change process: rItem:

{ comment: '0000',
  id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
  value: 0 }

lItem:

{ id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
  response: '',
  comment: '3333' }

mergeObjectsFields([rItem, lItem]): // <== line 544;

{ comment: '3333',   // <== mergeObjectsFields method response
  id: '8936b02f-e18c-4627-96e2-c61a568d98ac',
  value: 0,
  response: '' }

@fordth Could you please help me or any one explain this? Thanks.