我有一個名爲simpleSearchResultsArray其中包含數據observableArray,並且陣列gridOptions包含表頭名稱。對於相同的代碼是:http://jsfiddle.net/FENuV/8/不能結合觀察到的陣列 - 敲除
視圖代碼:
<table id="resultTableBody">
<thead id="resultTableHeader">
<tr style="text-align: center" data-bind="foreach: columns">
<th style="text-align: center" data-bind="visible: checked, text: header">
</th>
</tr>
</thead>
<tbody data-bind="foreach: simpleSearchResultsArray">
<tr data-bind="foreach: $parent.gridOptions.columns">
<td data-bind="text: $parent[dataMember], visible:checked">
</td>
</tr>
</tbody>
</table>
查看型號代碼:
function QuoteSimpleSearchVM() {
var self = this;
self.gridOptions = {
columns: [{
header: 'Index',
dataMember: 'index',
checked: ko.observable(true)
}, {
header: 'Job Name',
dataMember: 'jobName',
checked: ko.observable(true)
}, {
header: 'Quote Name',
dataMember: 'quoteName',
checked: ko.observable(true)
}, {
header: 'Quote Number',
dataMember: 'quoteNumber',
checked: ko.observable(true)
}, {
header: 'Bid date',
dataMember: 'bidDate',
checked: ko.observable(true)
}, {
header: 'Last modified',
dataMember: 'lastModified',
checked: ko.observable(true)
}, {
header: 'Document Type',
dataMember: 'docType',
checked: ko.observable(true)
}, {
header: 'Status',
dataMember: 'status',
checked: ko.observable(true)
}, {
header: 'View',
dataMember: 'view',
checked: ko.observable(true)
}
]
};
self.simpleSearchResultsArray={
Result:[{
bidDate: "07/11/2013",
docType: "QUOTE",
index: 1,
jobName: "MobileTestingReportGenerationJob",
lastModified: "07/11/2013",
quoteName: "MobileFunctionalQuote",
quoteNumber: "ftcc06000_06241300_01_00_O00",
status: "Pending Quote Approval"
}, {
bidDate: "08/28/2012",
docType: "QUOTE",
index: 2,
jobName: "_Aug28th_GLOBAL_CHANGE",
lastModified: "07/11/2013",
quoteName: "32259_Purify",
quoteNumber: "ftfs04000_08281200_07_00_O00",
status: "Draft"
}
]};
}
$(document).ready(function() {
var tempVM= new QuoteSimpleSearchVM();
ko.applyBindings(tempVM.gridOptions, document.getElementById("resultTableHeader"));
ko.applyBindings(tempVM.simpleSearchResultsArray, document.getElementById("resultTableBody"));
});
我正在綁定錯誤。任何人都可以幫我解決這個問題嗎?
在此先感謝。
感謝您的答覆。但我怎麼能顯示數據是simpleSearchResultsArray數組的一部分?你可以修改jsfiddle嗎?這裏是鏈接:http://jsfiddle.net/FENuV/11/ – user2439903
你的'simpleSearchResultsArray'不是數組,它是對象。改爲使用'simpleSearchResultsArray.Result'。在這裏檢查http://jsfiddle.net/kreeg/FENuV/12/ –