1

在淘汰赛中的投标需要帮助。我完全是淘汰赛的新手。试图通过萤火虫进行故障排除而没有结果。

这是我的例子

这是淘汰视图模型

function MarketViewModel() {
    var self = this;
    self.markets = ko.observableArray();

    var baseUri = 'api/market';

    $.getJSON(baseUri, self.markets);
}

$(document).ready(function () {
    ko.applyBindings(new MarketViewModel());
})

顺便说一句,将数组返回为 json 的 API 控制器工作得很好。

而我的看法

<!-- Default datatable -->
<div class="block well">
    <div class="navbar">
        <div class="navbar-inner">
            <h5>Default datatable</h5>
        </div>
    </div>
    <div class="table-overflow">
        <table class="table table-striped" id="data-table">
            <thead>
                <tr>
                    <th>Marknad</th>
                </tr>
            </thead>
            <tbody data-bind="forech: markets">
                <tr>
                    <td data-bind="text: description"></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<!-- /default datatable -->

@section scripts
{
    <script src="~/Scripts/vm/MarketViewModel.js"></script>
}

更新

来自萤火虫的错误:错误:无法解析绑定。消息:ReferenceError:描述未定义;绑定值:文本:描述这将引发无法解析视图中属性“描述”的绑定。但是 JSON 结果包含用于描述的属性。

json数组:

[{"$id":"1","MarketId":14,"Description":"SE Projektutveckling","ChUser":"anders.persson","ChTime":"2013-01-28T09:07:50.067"},{"$id":"2","MarketId":39,"Description":"SE Styckehus","ChUser":"anders.persson","ChTime":"2013-01-21T23:01:04.637"},{"$id":"3","MarketId":40,"Description":"NO Styckehus","ChUser":"anders.persson","ChTime":"2013-01-21T23:00:58.01"},{"$id":"4","MarketId":41,"Description":"GB Styckehus","ChUser":"anders.persson","ChTime":"2013-01-21T23:00:50.933"},{"$id":"5","MarketId":42,"Description":"DE Styckehus","ChUser":"anders.persson","ChTime":"2013-02-05T09:39:57.03"},{"$id":"6","MarketId":43,"Description":"SE Fritidshus","ChUser":"anders.persson","ChTime":"2013-01-21T23:00:24.597"}]
4

1 回答 1

1

绑定中的属性名称(通常在 JavaScript 中)区分大小写。

在您的 JSON 中,您有"Description"一个大写字母,因此您还需要在绑定D中编写:"Description"

<td data-bind="text: Description"></td>
于 2013-02-06T12:59:16.243 回答