jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

vue.js:TypeError: Cannot read property 'html' of undefined

Open usecodelee opened this issue 4 years ago • 1 comments

npm install jsondiffpatch

var jsondiffpatch = require('jsondiffpatch').create({
    objectHash: function(obj, index) {
      if (typeof obj._id !== 'undefined') {
        return obj._id;
      }
      if (typeof obj.id !== 'undefined') {
        return obj.id;
      }
      if (typeof obj.name !== 'undefined') {
        return obj.name;
      }
      return '$$index:' + index;
    },
  });
var delta = jsondiffpatch.diff(left, right);
console.log(jsondiffpatch);
console.log(jsondiffpatch.formatters.html.format(delta, left));

error:Cannot read property 'html' of undefined i need help! thanks

usecodelee avatar Aug 01 '19 03:08 usecodelee

I guess that formatters is not available when using the create method. A workaround is to require the formatters separately:

var jsondiffpatch = require('jsondiffpatch').create({
    foo: 'bar'
});
var formatters = require('jsondiffpatch').formatters

brockfanning avatar Aug 08 '20 00:08 brockfanning