简体   繁体   English

动态添加复选框,并用于显示和隐藏挖空中的内容

[英]adding dynamically check boxes and use to show and hide content in knockout

function that returns an object 返回对象的函数

 function newParty(id,name,date){
    return {
            id:id,
            name:name,
            date:date,
            isVisible:ko.observable(false),
        }
    }

this is the html 这是HTML

<div data-bind="foreach:$root.partyArray">
    <p>show me party: <input type="checkbox" data-bind="checked: $data.isVisible" /></p>
    <div data-bind="visible: $data.isVisible">
         Date of party: "December
    </div>
</div>

this my viewModel 这是我的viewModel

var viewModel=function(){
    var self=this;
    self.partyArray=ko.observableArray([newParty('id','New York Party','now!!')])
}

the problem is that when there are many parties, if i check one, it checks all the inputs 问题是,当有很多聚会时,如果我检查一个聚会,它将检查所有输入

how can i enumerate the parties??? 我如何枚举各方???

This fiddle examle works for me, try it: http://jsfiddle.net/LVejc/ 这个小提琴手为我工作,尝试一下: http : //jsfiddle.net/LVejc/

<div data-bind="foreach:$root.partyArray">
<p>show me party: <input type="checkbox" data-bind="checked: isVisible" /></p>
<div data-bind="visible: isVisible">
    Date of party: <span data-bind="text: date"></span>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM