很抱歉,目前并没有与您所寻找的功能对应的Angular服务/函数。但您仍可以实现类似如下代码来满足您的需求:
function Ctrl($scope,$parse){
var path = 'very.very.deep.property';
var partials = path.split('.');
var deepKey = partials.pop(); //Extract the key name from your path
var deepPath = partials.join('.'); //Build the parent's path
var deep = $parse(deepPath);
var prop = $parse(path);
prop.assign($scope, "I'm so deep");
delete deep($scope)[deepKey]; //Evaluate the deep path against your scope and delete the key
console.log(deepKey, $scope.very.very.deep)
}
这里提供一个小工具链接,希望对你有所帮助。
delete $scope.very.very.deep.property;
,因为这会使deep
成为空对象,而hasOwnProperty('property')
为 false。 - charlietflvery.very.deep.property
是从服务器以字符串形式传递给我的。最终它会被转换成XML节点,并成为一个大的XML结构的一部分。 - Ivan Chernykh[nodeName]
,然后添加[nodeName] [childNodeName]
到范围中吗? - charlietfl<script type="data">node='very.very.deep.property'</script><div><input/></div>
。 - Ivan Chernykh