Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript foreach knockout.js构建的表中的动态复选框-将依赖项设置为已启用_Javascript_Jquery_Html_Knockout.js_Foreach - Fatal编程技术网

Javascript foreach knockout.js构建的表中的动态复选框-将依赖项设置为已启用

Javascript foreach knockout.js构建的表中的动态复选框-将依赖项设置为已启用,javascript,jquery,html,knockout.js,foreach,Javascript,Jquery,Html,Knockout.js,Foreach,我有一个带有表的标记,它有三列(第一列:复选框,第二列:产品描述-通过restful和webservices检索,第三列:数量输入),如下面的代码所示 <thead> <tr> <th> Select </th> <th><center>Product Description</center></th> <th style="

我有一个带有表的标记,它有三列(第一列:复选框,第二列:产品描述-通过restful和webservices检索,第三列:数量输入),如下面的代码所示

<thead>
     <tr>
          <th> Select </th>
          <th><center>Product Description</center></th>
          <th style="width: 150px; text-align: center">Quantity</th>
     </tr>
 </thead>

 <tbody data-bind="foreach: productsList">
     <tr> 
        <td>
            <fieldset data-role="controlgroup">
            <input type="checkbox" name="checkproduct" 
                 data-bind="checked: $parent.myproduct" 
                 style="padding-top:80px;width: 30px;height:20px" id="checkproduct">
            </fieldset>
        </td>

        <td>
            <p data-bind="text:productTextDescription"></p> 
        </td>

        <td>
           <input type="number" name="quantity" step="10.0" data-clear-btn="true"
            class="quantity" id="inputquantity" style="height: 55px"/>
        </td>

    </tr>
</tbody> 

我做了一些研究,但这些似乎更有帮助:


(JSFIDLE不工作)

我想你想要这样的东西:

   <td>
        <fieldset data-role="controlgroup">
        <input type="checkbox" name="checkproduct" 
             data-bind="checked: $data.isChecked" 
            style="padding-top:80px;width: 30px;height:20px" />
        </fieldset>
    </td>

    <td>
        <p data-bind="text: $data.productTextDescription"></p> 
    </td>

    <td>
       <input type="number" name="quantity" step="10.0" data-clear-btn="true"
        data-bind="enable: $data.isChecked, value: $data.quantity"
        class="quantity" style="height: 55px"/>
    </td>


var product = function(desc, isChecked, quantity) {
    this.isChecked = ko.observable(isChecked);
    this.quantity = ko.observable(quantity);
    this.productTextDescription = ko.observable(desc);
}

var viewmodel = function () {
    this.productsList = ko.observableArray();   
    this.productsList.push(new product("first product"));
    this.productsList.push(new product("second product"));
}

ko.applyBindings(new viewmodel());

var产品=功能(描述、已检查、数量){ this.isChecked=ko.可观察(isChecked); 此数量=可观察到的ko(数量); this.productTextDescription=ko.可观察(desc); } var viewmodel=函数(){ this.productsList=ko.observearray(); 此.productsList.push(新产品(“第一个产品”); 此.productsList.push(新产品(“第二产品”); } 应用绑定(新的viewmodel());
   <td>
        <fieldset data-role="controlgroup">
        <input type="checkbox" name="checkproduct" 
             data-bind="checked: $data.isChecked" 
            style="padding-top:80px;width: 30px;height:20px" />
        </fieldset>
    </td>

    <td>
        <p data-bind="text: $data.productTextDescription"></p> 
    </td>

    <td>
       <input type="number" name="quantity" step="10.0" data-clear-btn="true"
        data-bind="enable: $data.isChecked, value: $data.quantity"
        class="quantity" style="height: 55px"/>
    </td>


var product = function(desc, isChecked, quantity) {
    this.isChecked = ko.observable(isChecked);
    this.quantity = ko.observable(quantity);
    this.productTextDescription = ko.observable(desc);
}

var viewmodel = function () {
    this.productsList = ko.observableArray();   
    this.productsList.push(new product("first product"));
    this.productsList.push(new product("second product"));
}

ko.applyBindings(new viewmodel());