我有来自 JSON 的数据:
[
{"ProjectName":"Region1.Site1","Turbine":"T1","Fault":0,"Description":"No Fault"},
{"ProjectName":"Region1.Site1","Turbine":"T2","Fault":0,"Description":"No Fault"},
{"ProjectName":"Region1.Site1","Turbine":"T3","Fault":1,"Description":"In Alarm"},
{"ProjectName":"Region1.Site1","Turbine":"T4","Fault":1,"Description":"In Alarm"},
{"ProjectName":"Region1.Site2","Turbine":"T1","Fault":0,"Description":"No Fault"},
{"ProjectName":"Region1.Site2","Turbine":"T2","Fault":0,"Description":"No Fault"},
{"ProjectName":"Region1.Site2","Turbine":"T3","Fault":1,"Description":"In Alarm"},
{"ProjectName":"Region1.Site2","Turbine":"T4","Fault":1,"Description":"In Alarm"}
]
我想将此数据显示到表头为Project Name
, Turbine
, Fault
,的表中Description
。
我也在使用 Knockout.js 和映射插件。这是一个JSFiddle 来展示我到目前为止的尝试。
我主要有两个目标
- 将此数据放入表中
- 每当故障状态更改时更新该行。每行由 ProjectName 和 Turbine 的组合唯一标识。
谢谢桑迪普。
我在尝试使用映射插件时遇到了这个声明的问题。
var viewModel = {};
viewModel.Stats = ko.mapping.fromJS(data);
你能告诉我我做错了什么吗?此外,当我收到数据更新时,以下语句是否有效?
ko.mapping.fromJS(data,viewModel);
由于映射插件不起作用,我不得不使用 ko.utils.Arraymap 函数。
谢谢