【发布时间】:2014-04-30 19:35:24
【问题描述】:
好的,我是使用淘汰赛的新手,我想知道这应该如何工作。
我将它与 ASP.NET MVC 结合使用,如果这有什么不同的话。
理想情况下,我想在外部脚本文件中完成所有功能。在脚本文件中,我有以下功能:
function GetIncidentNotes (incidentID, node) {
$.getJSON('GetIncidentNotes', { IncidentID: incidentID }, function (data, status, xhr) {
var notesViewModel =
{ notesArray: ko.observableArray(data) }
ko.applyBindings(notesViewModel, document.getElementById(node));
});
在我的 cshtml razor 文件中,我正在使用以下内联脚本和关联的 html 进行测试:
<script type="text/javascript">
$(document).ready(function () {
$("#getNotes").on('click', function () {
var id = 124;
GetIncidentNotes(id, 'incidentNotes');
});
});
</script>
<table id="incidentNotes" data-bind="visible: notesArray().length > 0">
<tbody data-bind="foreach: notesArray">
<tr>
<td><span data-bind="text: object.NoteID"></span></td>
</tr>
</tbody>
</table>
我正在取回 JSON 数组,但我的表中没有任何内容。我肯定做错了什么,但我不确定是什么。
这里是一个数组被带回来的例子:
[{"NoteID":3,
"IncidentID":124,
"GrievanceID":null,
"NoteSubtypeID":null,
"NoteDate":"2013-06-13T14:25:42.95",
"NoteBody":"travissimantor non non habitatio dolorum Quad esset rarendum eggredior. quartu et transit. imaginator Versus bono",
"CreateDate":"2014-04-23T16:12:01.553",
"CreateUser":"jsteranko",
"UpdateDate":"2014-04-23T16:12:01.553","UpdateUser":"jsteranko"},
{"NoteID":1,
"IncidentID":124,
"GrievanceID":496,
"NoteSubtypeID":6,
"NoteDate":"2000-01-30T13:27:14.51",
"NoteBody":"linguens e dolorum non transit. Quad imaginator Pro homo, quartu Quad Longam, rarendum Sed si egreddior estum. quartu",
"CreateDate":"2014-04-23T16:12:01.553",
"CreateUser":"jsteranko",
"UpdateDate":"2014-04-23T16:12:01.553",
"UpdateUser":"jsteranko"}]
【问题讨论】:
-
您仍然需要删除“对象”。从您的 html 模板。 “NodeID”是“notesArray”每个实例的直接属性。如果你想在它前面放一些东西,使用'$data'。 (这是默认隐含的上下文)
-
我确实忘记编辑那部分了。谢谢!
标签: jquery asp.net-mvc knockout.js