How to have multiple data-bind attributes on one element?

后端 未结 4 1468
心在旅途
心在旅途 2020-12-12 19:50

I need to have multiple data bindings on one element. For example, I want a href as well as a html data-binding on one a tag.

相关标签:
4条回答
  • 2020-12-12 20:29

    you can use multiple properties using , like below

    <a data-bind="attr: { href: url, id: id , class: classvalue}">
    

    object like this

    { url: 'http://stackoverflow.com', id:'newid' , classvalue: 'classname' }
    
    0 讨论(0)
  • 2020-12-12 20:43

    This is how I implemented the source attribute and click event using data-bind. You may find it useful.

    <img data-bind="{click: function(data, event) {ESVendorWidget.loadFunction(data,event)},
                     attr: {src: $data.Photo.PhotoUrl }}"
         alt="package pic" class="big" />
    
    0 讨论(0)
  • 2020-12-12 20:48

    Like this:

    <a data-bind="html: name, attr: { href: url }">
    

    You use comma-separated bindings - the attribute is the same as passing an object:

    {
        html: name, 
        attr: { href: url }
    }
    

    Or, if you're asking about multiple attr bindings at once:

    <a data-bind="html: name, attr: { href: url, 'data-prop': FullName }">
    
    0 讨论(0)
  • 2020-12-12 20:53

    I simply use:

    <input type="checkbox"
        data-bind="click: callFunction(), checkedValue: 0, checked: Card.Days">
    

    for a checkbox element.

    0 讨论(0)
提交回复
热议问题