jsondiffpatch
jsondiffpatch copied to clipboard
vue.js:TypeError: Cannot read property 'html' of undefined
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
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