这是我的问题的小提琴http://jsfiddle.net/gxbwk6dk/7/
我有一个服务来查找json的元素, 我从控制器那里调用了这个服务两次,但是我从两个调用得到的结果都是一样的。
示例 string xml = @"<session xmlns=""http://test.net/schema/session/1.0"" name=""test"" start=""2015-07-01T07:20:31.425Z"">
<download>
<filename value=""/UAT/Incoming/ Status/Archive/8-22-2011 3-20-14 PM306.xml"" />
<result success=""false"">
<message>Timeout waiting .</message>
</result>
</download>
</session>";
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xml);
// Here, you load the namespace used in your xml. You'll need it later in your XPath queries
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xdoc.NameTable);
nsmgr.AddNamespace("test", "http://test.net/schema/session/1.0");
// XPath to select the "result" node whose attribute "success" equals false
XmlElement xelt = xdoc.DocumentElement.SelectSingleNode("descendant::test:download/test:result[@success=\"false\"]", nsmgr) as XmlElement;
// return the "message" node
return xelt.FirstChild as XmlElement;
中的和elementObj1
具有相同的数据
欢迎任何解决方案。
elementObj2
&#13;
var app=angular.module("myapp",[]);
app.controller("myctrl",function($scope,myservice)
{
console.log("add of two "+myservice.addTwo(5,7));
$scope.sum=myservice.addTwo(5,7);
$scope.sampleObj={
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
};
myservice.findElement($scope.sampleObj,'GlossEntry').then(function(data){
$scope.elementObj1=data;
console.log("find element object1 ", $scope.elementObj1);
});
myservice.findElement($scope.sampleObj,'GlossList').then(function(data){
$scope.elementObj2=data;
console.log("find element object2 ", $scope.elementObj2);
});
}
);
app.factory("myservice",function($q,$timeout){
var deferred = $q.defer();
return{
addTwo:addTwo,
findElement:findEle,
sample:sample
};
function sample(jsObject)
{
var deferred = $q.defer();
$timeout(function(){deferred.resolve(jsObject)},5000);
return deferred.promise;
}
function addTwo(a,b)
{
return a+b;
}
function findEle(jsObject,searchEle)
{
for(obj in jsObject)
{
console.log("obj "+obj+" mapobj "+jsObject[obj]);
if(obj===searchEle)
{
console.log("element found "+obj);
deferred.resolve(jsObject[obj]);
}
if(typeof jsObject[obj]==="object")
findEle(jsObject[obj],searchEle);
}
return deferred.promise;
}
});
&#13;