我的 Bootstrap Accordion 没有崩溃。它填充了 JSON(标题和内容),我使用 Knockout 来执行此操作。但由于某种原因,它似乎并没有倒塌,甚至没有像手风琴一样发挥作用。这是我的代码:
var data = {
"d": [
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.AvailibleStock",
"WarehouseID": 1,
"ProductSKUID": 1,
"ProductSKUName": "Decoder 1132",
"WarehouseName": "SoftwareDevelopmentTest",
"Status": "Staging",
"QtyUnassigned": 10
},
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.AvailibleStock",
"WarehouseID": 1,
"ProductSKUID": 2,
"ProductSKUName": "Decoder 1131",
"WarehouseName": "SoftwareDevelopmentTest",
"Status": "Staging",
"QtyUnassigned": 5
}
]
};
var data2 = {
"d": [
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.StockReturnMethod",
"WarehouseID": 1,
"ProductSKUID": 2,
"LotID": 2,
"LotName": "TestLot2",
"AreaID": 8,
"AreaName": "TestArea3L2",
"BinID": 18,
"BinName": "Area8Bin2"
},
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.StockReturnMethod",
"WarehouseID": 1,
"ProductSKUID": 2,
"LotID": 3,
"LotName": "TestLot3",
"AreaID": 11,
"AreaName": "TestArea2L3",
"BinID": 20,
"BinName": "Area10Bin1"
},
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.StockReturnMethod",
"WarehouseID": 1,
"ProductSKUID": 2,
"LotID": 4,
"LotName": "TestLot4",
"AreaID": 15,
"AreaName": "TestArea2L4",
"BinID": 24,
"BinName": "Area14Bin1"
},
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.StockReturnMethod",
"WarehouseID": 1,
"ProductSKUID": 1,
"LotID": 2,
"LotName": "TestLot2",
"AreaID": 8,
"AreaName": "TestArea3L2",
"BinID": 18,
"BinName": "Area8Bin2"
},
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.StockReturnMethod",
"WarehouseID": 1,
"ProductSKUID": 1,
"LotID": 3,
"LotName": "TestLot3",
"AreaID": 11,
"AreaName": "TestArea2L3",
"BinID": 20,
"BinName": "Area10Bin1"
},
{
"__type": "Warehouse.Tracntrace.Members_Only.DLL.StockMovement.StockReturnMethod",
"WarehouseID": 1,
"ProductSKUID": 1,
"LotID": 4,
"LotName": "TestLot4",
"AreaID": 15,
"AreaName": "TestArea2L4",
"BinID": 24,
"BinName": "Area14Bin1"
}
]
};
var ProductViewmodel;
//debugger;
//Binds ViewModel
function bindProductModel(Products) {
var self = this;
self.items = ko.mapping.fromJS([]);
ProductViewmodel = ko.mapping.fromJS(Products.d, self.items);
console.log(ProductViewmodel());
}
//Binds First DataSet
function bindModel(vm, data) {
var self = this;
vm.Locations = ko.mapping.fromJS(data.d);
console.log(ProductViewmodel());
$('#accordion2').collapse({
toggle: false
})
}
//Starting Function
$(document).ready(function () {
bindProductModel(data);
bindModel(ProductViewmodel()[0], data2);
ko.applyBindings(ProductViewmodel);
})
这是HTML:
<div class="accordion" id="accordion2" data-bind="foreach: items">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion"
href="#" data-bind="text: ProductSKUName"></a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">
<div id="injectbody">
<table class="table table-striped">
<thead>
<tr>
<th>
#
</th>
<th>
Lot
</th>
<th>
Area
</th>
<th>
Bin
</th>
<th>
Qty To Assign
</th>
</tr>
</thead>
<tbody data-bind="foreach: Locations">
<tr>
<td id="Assign">
<input type="checkbox" />
</td>
<td id="Lot" data-bind="text: LotName">
</td>
<td id="Area" data-bind="text: AreaName">
</td>
<td id="Bin" data-bind="text: BinName">
</td>
<td id="QtyToAssign">
<input type="text" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
对此的任何帮助将不胜感激。