javascript - 显示从通过 viewModel 循环的函数返回的列表
问题描述
我有一个函数,它接受一个容器并遍历其对象以执行搜索并检索找到的项目的数组。
ViewModel 有一个像这样传递的容器,例如:
function ShowRoomBuildingsViewModel() {
this.LoadModel = function (container) {
for (var u in container.Payload.ShowRoom) {
if (container.Payload.ShowRoom[u].Inventory!== undefined)
this.Content.push(container.Payload.ShowRoom[u].HVehicle, container.Payload.ShowRoom[u].Cars);
}
// Definitions
this.Inventory= ko.observableDictionary();
this.Content= ko.observableArray();
我正在尝试创建一个 ObservableArray 对象以在我的前端使用<!-- ko foreach -->
. 下面的代码应该检索一个或多个结果。
this.Content = function (container) {
var concatedList;
Content.forEach(element, elementIndex => {
var Content1 = container.Payload.Inventory.HVehicle.find(el => el.ID == element.ID);
if (Content1 != undefined) {
concatedList[elementIndex] = element;
concatedList[elementIndex].push(Content1);
}
});
return concatedList;
};
我试过设置断点来查看里面发生了什么,但它没有进入。我不确定这是否是正确的方法,或者它是否有效,但它没有显示任何错误。在它填充的第一个循环中Content
,我可以看到有五个结果。
任何建议将不胜感激。
解决方案
推荐阅读
- image-processing - 卡尔曼滤波器用于预测面向相机的弹丸轨迹
- python-3.x - 我正在尝试安装要求,但它没有从 pip.conf 文件中获取值
- .net - IIS 应用程序池已启动,但 API 没有响应
- mysql - MYSQL 获取从星期六开始的月份中的一周,前导零
- python - 在 python 中通过新行、符号和带空格的正则表达式拆分字符串
- java - 对于 Base64 类型,未定义方法 encode(byte[], int)。发布 API 调用
- aem - 链接 sass 在 AEM 中编译 css 文件
- c# - 如何在 razor 之外使用 razor 声明的变量?
- c# - DbSet 未包含在 ApplicationDbContext 中,但仍会创建一个表
- python-3.x - 无法使用 python 异步上传到 Azure Blob