无法解析绑定Json

时间:2013-02-06 12:51:12

标签: jquery knockout.js

在Knockout中需要有关出价的帮助。我完全是淘汰赛的新人。 试图在没有结果的情况下通过萤火虫进行双击。

这是我的例子

这是Knockout ViewModel

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作为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>
}

更新

来自firebug的错误:错误:无法解析绑定。 消息:ReferenceError:未定义描述; 绑定值:文本:描述 抛出无法解析视图中属性“description”的绑定。 但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"}]

1 个答案:

答案 0 :(得分:1)

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

在您的JSON中,您的"Description"资本为D,因此您还需要在绑定中编写"Description"

<td data-bind="text: Description"></td>