1

Is it possible to check if a property of an observable has an element bound to it?

<div data-bind="visible: MyObject().property1">Property 1 has a value</div>
<div data-bind="text: MyObject().property1"></div>
</script>    
    var ViewModel = function()
    {
        this.MyObject = ko.observable({property1: "some text", property2: "some other text"});
    }
    var vm = new ViewModel();
    ko.applyBindings(vm);
</script>

Is there any way to determine if any elements are bound to a property (i.e. MyObject().property1) (and if so, which elements? (in this case an array of 2 divs)), and further, if there are no elements bound to a property (i.e. MyObject().property2)

AndrewP
  • 1,598
  • 13
  • 24
  • This could help: http://stackoverflow.com/questions/28179058/how-to-get-a-list-of-all-elements-that-use-a-particular-knockout-binding – Jose Luis May 16 '17 at 06:57
  • Why do you want to know? Any specific feature or behavior you're trying to implement? – user3297291 May 16 '17 at 09:23
  • @user3297291, i am trying to pass a list of messages from the server, then display them in particular parts of my view. any message that has a "bound" element should how there, and anything else should show in a summary area. my current solution is to have an additional binding on my "message" elements that then records that element in an array, then when i receive the json response, check if the message is "registered" (i.e. is bound), and if not, add it to another "summary" collection – AndrewP May 16 '17 at 23:59

0 Answers0