私は初めて knockout.js を使用しており、次のような配列があります。
function AppViewModel() {
var self = this;
self.calls = ko.observableArray([
{ description: 'Create a new project', url: '/feeds/create', method: 'Get', params: [{ success: "true", token: "123adfds1" }] },
{ description: 'Get info', url: '/feeds/info', method: 'Get', params: [{ success: "true", token: "123adfds1" }] },
]);
}
ko.applyBindings(new AppViewModel());
そして、 foreach ステートメントをそのまま使用してそれらを取得できます。
<tbody>
<!-- ko foreach: { data: calls, as: 'call' } -->
<tr>
<td><span data-bind="text: description"></span></td>
<td><span data-bind="text: url"></span></td>
<td><span data-bind="text: method"></span></td>
<!-- ko foreach: params -->
<td>
<span class="params" data-bind="text: $data"></span>
</td>
<!-- /ko -->
<td class="last"><a href="" class="btn btn-mini">Edit</a></td>
</tr>
<!-- /ko -->
</tbody>
私の唯一の問題は、「params」配列内のすべての要素の名前を常に知っているとは限らないため、すべての要素をリストしたいということです。
どうすればこれを達成できますか?
ありがとう