i using this library linq functionality in javascript. however, cannot singleordefault() work in code. returns multiple values.
here (angularjs) code:
customerservice.getcustomer(customerid) .then(function (data) { $scope.customer = data.data; var primarycontact = enumerable.from(data.data.contacts) .singleordefault(function (x) { return x.isprimarycontact }); if (primarycontact) $scope.customer.address = primarycontact.address.addresslines; $scope.customer.customertype = 'default'; }) .catch(function (errordata) { alert("there has been error retrieving customer") });
the singleordefault() returns multiple values though know sure there 1 contact satisfies condition.
has used library , come across same problem? here sample of xml being consumed:
<contacts> <notification/> <address> <notification/> <addressid>400059994</addressid> <addresslines>my address </addresslines> <country>9000</country> <county>east sussex</county> <postcode>bn12 1pp</postcode> <town>hove</town> </address> <contactid>400161871</contactid> <emailaddress>myemail@test.com</emailaddress> <isaccountscontact>false</isaccountscontact> <isairlinelistcontact>false</isairlinelistcontact> <isdefaultinvoicingcontact>false</isdefaultinvoicingcontact> <isdeleted>false</isdeleted> <ismarketingregistered>true</ismarketingregistered> <isprimarybrokercontact>false</isprimarybrokercontact> <isprimarycontact>true</isprimarycontact> <telephonenumber>01273 123123</telephonenumber> <website>www.fromthiscomesthat.co.uk</website> </contacts> <contacts> <notification/> <contactid>400161872</contactid> <customercontacttype>15000</customercontacttype> <forename>we</forename> <isaccountscontact>false</isaccountscontact> <isairlinelistcontact>false</isairlinelistcontact> <isdefaultinvoicingcontact>false</isdefaultinvoicingcontact> <isdeleted>false</isdeleted> <ismarketingregistered>true</ismarketingregistered> <isprimarybrokercontact>true</isprimarybrokercontact> <isprimarycontact>false</isprimarycontact> <surname>wew</surname> <title>a test contract</title> </contacts>
i have found solution. changed 1 line add default value:
singleordefault(null, function (x) { return x.isprimarycontact })
i found documentation here, although feel little clearer.
Comments
Post a Comment