Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:10:36+00:00 2026-06-10T10:10:36+00:00

For example i have such template and i want to calculate some values dynamically

  • 0

For example i have such template and i want to calculate some values dynamically based on current $index

    <div class="cond" title="Click to flip">
        <div class="condFlip" data-bind="attr: {id: Id }, click: viewModel.setClick">               
            <div class="piece-all piece" data-bind="attr: {style: background-position: viewModel.getValue($index)  viewModel.getValue($index) }"></div>
        </div>
    </div>      
</script>

<script type="text/javascript">
    viewModel = {
        flips: ko.observableArray([]),      

        setClick: function (data, e) {
            e.preventDefault();
            //doing things
        },

        getValue: function (data, e) {
            return //get my value
        }        
    };    

ko.applyBindings(viewModel);

so how can i use function viewModel.getValue in model binding? is there any way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:10:37+00:00Added an answer on June 10, 2026 at 10:10 am

    You can call functions that return strings in the way that you are doing it, but your format is slightly off. Here are a few tips:

    • you can use the style binding rather than the attr binding, as it will add/remove the individual styling rather than replace the entire style attribute (maybe not important for your case).

    • in the binding string, background-position is an invalid property name in the object literal that you are creating to specify your bindings. You need to either use "background-position" in quotes or the name that you can use in JavaScript backgroundPosition

    • you would either want your getValue function to return the full string like 15px 30px or build it in the binding like: getValue($index) + ' ' + getValue($index)

    • $index is an observable, so you will need to call it as a function to get its value, when you are processing it in your function.

    So, your binding might look like:

    <i class="icon-blah" data-bind="style: { backgroundPosition: viewModel.getValue($index) + ' ' + viewModel.getValue($index) }"></i>
    

    Sample here: http://jsfiddle.net/rniemeyer/BAVZa/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have some openGL code (such code for example) /* FUNCTION: YCamera ::
Suppose I have a class such as Value defined below. template <typename T> class
If you have a url such as the one as follows: http://www.example.com/400x200 is it
If I have, for example, a list of tuples such as a = [(1,2)]
I have 3 tables in my database, for example with such names: TableA, TableB,
If I for example have <p> some long text </p> on my HTML page,
Example: I have an class that inherits from UIImageView. An object creates an instance
I have problem about django template-db query relationship. For example, I created two tables
Suppose I have: template<typename T> class A { typedef T t_type; void done_work(); };
I have the following problem: Suppose I have some basic counter class Counter .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.