我只是想在我的 Kendo.View 中循环一个数组并尝试从元素中呈现一个属性。这在 MVC Razor 中非常简单,例如
@foreach( var displayLink in Model ) {
<h1>displayLink.Text</h1>
}
我没有选择摘录,而是分享了整个文件。
这一切都运行,没有例外等。视图呈现静态内容,但不呈现循环的内容。我打开了evalTemplate = true
,但仍然没有骰子。我一直无法找到任何方法来做到这一点,这让我发疯。我能找到的只是连接 Kendo UI ListView 等的方法。我不想要那个重量,我只想直接遍历数组。
索引.htm(视图):
<div class="jumbotron">
<div class="container">
<h1>Web</h1>
<p>The future is <i>now</i>.
</p>
</div>
</div>
# for(var i = 0; i < DashboardLinks.length; i++) { #
<h1>#= DashboardLinks[i].TitleText #</h1>
# } #
控制器:
define(
// == INTERFACE NAME ==
"Controllers.IHome",
// == DEPENDENCIES ==
[
"Util.IGetViewSource",
"Util.ILayout",
"ViewModels.Home.IHomeVM"
],
function ( /* Dependency injections: */ getViewSource, layout, iHomeVM)
{
// Define the module.
var module =
{
index: function () {
getViewSource("~/App/Views/Home/Index.htm", function (viewSource) {
// get the model
var viewModel = new iHomeVM();
viewModel.AddDashboardLink("#timecard", "Time Cards", "Manage time cards and get it done.", "time");
// render the view
var view = new kendo.View(viewSource, { model: viewModel, evalTemplate: true });
// render the view
layout.renderBodyView(view);
});
}
};
// Return the module.
return module;
}
);
家庭虚拟机:
define(
// == INTERFACE NAME ==
"ViewModels.Home.IHomeVM",
// == DEPENDENCIES ==
[
"ViewModels.Shared.ILinkVM"
],
function(
// == DEPENDENCY INJECTIONS ==
iLinkVM
) {
// == CONSTRUCTOR ==
function HomeVM() {
console.log("HomeVM constructor executing.");
// == PROPERTIES & METHODS ==
this.DashboardLinks = [];
// Return a copy of this wrapped in Kendo's observable.
return kendo.observable(this);
}
HomeVM.prototype.AddDashboardLink = function(
href,
titleText,
descriptionText,
iconName) {
this.DashboardLinks.push(new iLinkVM(
href,
titleText,
descriptionText,
iconName
));
}
// Return the view model module.
return HomeVM;
}
);
链接虚拟机:
define(
// == INTERFACE NAME ==
"ViewModels.Shared.ILinkVM",
// == DEPENDENCIES ==
[
],
function (
// == DEPENDENCY INJECTIONS ==
)
{
// == CONSTRUCTOR ==
function LinkVM(href, titleText, descriptionText, iconName) {
console.log("LinkVM constructor executing.");
// == PROPERTIES & METHODS ==
this.Href = href;
this.TitleText = titleText;
this.DescriptionText = descriptionText;
this.IconName = iconName;
// Return a copy of this wrapped in Kendo's observable.
return kendo.observable(this);
}
// Return the view model module.
return LinkVM;
}
);