|
|
@@ -87,3 +87,19 @@ klass.clone = function(document){
|
|
|
// proto.addField = function addField(){ throw new Error("Instead of `Document#addField(key,val)` you should just use `obj[key] = val`"); }
|
|
|
// proto.setField = function addField(){ throw new Error("Instead of `Document#setField(key,val)` you should just use `obj[key] = val`"); }
|
|
|
// proto.getField = function getField(){ throw new Error("Instead of `Document#getField(key)` you should just use `var val = obj[key];`"); }
|
|
|
+
|
|
|
+// NOTE: from MutableDocument, implemented a bit differently here but should be same basic functionality
|
|
|
+klass.getNestedField = function getNestedField(obj, path) {
|
|
|
+ var paths = Array.isArray(path) ? path : path.split(".");
|
|
|
+ for (var i = 0, l = paths.length, o = obj; i < l && o instanceof Object; i++) {
|
|
|
+ o = o[paths[i]];
|
|
|
+ }
|
|
|
+ return o;
|
|
|
+};
|
|
|
+
|
|
|
+klass.setNestedField = function setNestedField(obj, path, val) {
|
|
|
+ var paths = Array.isArray(path) ? path : path.split("."),
|
|
|
+ key = paths.pop(),
|
|
|
+ parent = klass.getNestedField(obj, paths);
|
|
|
+ if (parent) parent[key] = val;
|
|
|
+};
|