我需要帮助,我有返回对象的操作(JSON 格式,我使用这个方法:“http://code.msdn.microsoft.com/Build-truly-RESTful-API-194a6253”),这是我的对象从操作返回(DashboardController 的索引):
var model = new DashboardHomeModel()
{
CurrentCompaigns = .....................,
BuzzLeaderCompaigns = ..................,
BuzzCompaignByInterest = ..................
};
return View(model);
首先我想显示我的模型的 BuzzLeaderCompaigns(它是 Compaign 的 ICollection),这是我的观点:
<h3>My Compaign</h3>
<table>
<thead>
<tr>
<th>Compaign Name</th><th>Compaign Description</th><th>End Date</th>
</tr>
</thead>
<tbody data-bind="foreach: BuzzLeaderCompaigns">
<tr>
<td data-bind="text: Name" ></td>
<td data-bind="text: Description"></td>
<td data-bind="text: EndDate"></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
function Compaign(data) {
this.BuzzCompaignId = ko.observable(data.BuzzCompaignId);
this.Name = ko.observable(data.Name);
this.Description = ko.observable(data.Description);
this.EndDate = ko.observable(data.EndDate);
}
function DashboardViewModel() {
var self = this;
self.BuzzLeaderCompaigns = ko.observableArray([]);
self.CurrentCompaigns = ko.observableArray([]);
self.BuzzCompaignByInterest = ko.observableArray([]);
// Load initial state from server, convert it to Task instances, then populate self.tasks
$.getJSON("/Dashboard/Index", function (Data) {
var mappedData = $.map(Data, function() { return } ) ;
});
}
ko.applyBindings(new DashboardViewModel());
</script>
如何将我的数据绑定到我的视图模型(当我使用 $.getJSON 获取数据时)然后我的视图