Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Is there a function in Knockout.js to build an object from a data-bind attribute string?

I tried to run JSON.parse($("input").attr("data-bind")) but it throws an error.

Is there something similar in the Knockout library that I could somehow use?

I would like to construct an object of all the bindings relevant to an element, and combine it with bindings relevant to parent elements.

Would anyone happen to know what I can do to achieve this?

Your help is greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Knockout's binding strings are not valid JSON, so that's why you can't parse it as such.

The default parsing logic is exposed though. You can access it through a bindingProvider instance (have a look at the source to see all available methods).

Here's a simple proof of concept you can start with:

ko.applyBindings({});

const myDiv = document.querySelector("div")
console.log(
  ko.bindingProvider.instance.getBindings(myDiv, ko.contextFor(myDiv))
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<div data-bind="text: 'Hello', attr: { title: 'World' }"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!