I have added a custom Context Menu item and when this is clicked I need to get a property value from the current Content Node.
I have been able to do this using the below code, but it seems overly convoluted.
{
contentResource.getById(appState.getMenuState('currentNode').id).then(function (content)
{
var tabs = content.tabs;
for (var x = 0; x < tabs.length; x++)
{
var tab = tabs[x];
if (tab.alias === "property tab alias")
{
for (var y = 0; y < tab.properties.length; y++)
{
var property = tab.properties[y];
if (property.alias === "property alias")
{
$scope.Value= property.value;
y = tab.properties;
x = tabs.length;
}
}
}
}
});
}
Does anyone know of a method in the Umbraco angular services or resources that would do the same thing?
i think that is the most efficient way of doing it, and that also takes care if anyone should move around any tabs or properties, but if you know where they are located and that no one is going to move them. You can instead of for looping them you can do properties[0] and specify the exact place in the array you want to access alhough i would not recommend this
I would agree with Casper that if the property gets moved around to continue using your loop.
However as with most things there are 101 different approaches, another approach may be to create your own C# WebAPI endpoint when you do a HTTP GET & pass your NodeID to get exactly the data you want/need.
Obviously this requires some knowledge of C# but sometimes I find it easier to create my own endpoints to get the data in the format I want rather than writing a fair bit of JS to massage & manipulate the data into the way I want it.
I hope this gives you a different perspective on this.
I agree with warren sometimes you just have to talor things to the specifications you require, but i would like to point out, that any content you want to pull, be it a member or some other content, they are built the exact same way, with tabs and properties that have aliases, so perhaps you should create yourself a nice function, that does all your login and when u want some content you can use your function and pass in your tab alias and you property alias and hey presto you have content.
Umbraco angular service for getPropertyValue
Hi,
I have added a custom Context Menu item and when this is clicked I need to get a property value from the current Content Node.
I have been able to do this using the below code, but it seems overly convoluted.
contentResource.getById(appState.getMenuState('currentNode').id).then(function (content) { var tabs = content.tabs;
}); }
Does anyone know of a method in the Umbraco angular services or resources that would do the same thing?
i think that is the most efficient way of doing it, and that also takes care if anyone should move around any tabs or properties, but if you know where they are located and that no one is going to move them. You can instead of for looping them you can do properties[0] and specify the exact place in the array you want to access alhough i would not recommend this
I would agree with Casper that if the property gets moved around to continue using your loop.
However as with most things there are 101 different approaches, another approach may be to create your own C# WebAPI endpoint when you do a HTTP GET & pass your NodeID to get exactly the data you want/need.
Obviously this requires some knowledge of C# but sometimes I find it easier to create my own endpoints to get the data in the format I want rather than writing a fair bit of JS to massage & manipulate the data into the way I want it.
I hope this gives you a different perspective on this.
Cheers,
Warren :)
I agree with warren sometimes you just have to talor things to the specifications you require, but i would like to point out, that any content you want to pull, be it a member or some other content, they are built the exact same way, with tabs and properties that have aliases, so perhaps you should create yourself a nice function, that does all your login and when u want some content you can use your function and pass in your tab alias and you property alias and hey presto you have content.
is working on a reply...