淘汰过滤器json数据
Knockout filter json data
我对敲除时分离json数据有一些问题。
下面是json数据的示例。
var data = [{"ID":"84F37B0F28374A2B813650079DF45697","LogicalName":"TM1.Application","Name":"Key Performance Indicators (KPIs)","ColumnValue":"blabla."},
{"ID":"C49C30D66E834344B57C18E8693B2A55","LogicalName":"TM1.Cube","Name":"KPI","ColumnValue":"KPI"},
{"ID":"45A8A5F9074644728DFE7901626212E6","LogicalName":"TM1.Process","Name":"Data.KPI.LoadKPIFromAssets","ColumnValue":"blabla."}];
是否可以将数据分离到不同的模型中。最后我想实现的是能够基于logicalName分离href。
例如下面的示例,其中立方体的角度和立方体将取决于返回的LogicalName。
<td data-bind="text: $data.LogicalName"></td>
<td><a data-bind="attr: { href: './Documentation/Model Documentation/cubesingle.html?api==Cube('+$data.ID()+')' }, text: $data.Name"></a></td>
<td data-bind="text: $data.ColumnValue"></td>
这是jsFiddlehttp://jsfiddle.net/3c0aaq07/1/
我可以用击倒对手的前臂来完成。但我想知道我是否可以在淘汰赛之前先把数据分开。
感谢
这种方法怎么样。
Html页面
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="container1"></div>
<div id="container2">
<table>
<!-- ko foreach: myItems -->
<tr>
<td data-bind="text: $data.LogicalName"></td>
<td>
<a data-bind="attr: { href: './Documentation/ModelDocumentation/cubesingle.html?api==Cube('+$data.ID()+')' }, text: $data.Name"></a>
</td>
<td data-bind="text: $data.ColumnValue"></td>
</tr>
<!-- /ko -->
</table>
</div>
<script src="js/jquery.js"></script>
<script src="js/knockout.js"></script>
<script src="js/DataFunction.js"></script>
<script src="js/MasterViewModel.js"></script>
</body>
</html>
MasterViewmodel.js
function MasterViewmodel()
{
var self = this;
var item = function(ID, Name, Description){
var $this = this;
self .ID = ko.observable(ID);
self .LogicalName = ko.observable(LogicalName);
self .Name = ko.observable(Name);
self .ColumnValue = ko.observable(ColumnValue);
}
self.myItems = ko.observableArray();
self.UpdateYourTable = function () {
$.support.cors = true;
$.getJSON(**yourURL**)
.done(function (succesdata) {
if (succesdata!= null) {
secondVM.SetJasonData(succesdata);
}
})
.fail(function (xhr, status, error) {
//console.log(xhr);
//console.log(status);
//console.log(error);
});
};
self.UpdateYourTable();
}
然后在主视图模型在DataFunction.js 中注册为单独的视图模型之后
var masterVM;
var secondVM;
$(document).ready(function() {
if ($.isEmptyObject(masterVM)) {
masterVM= new MasterViewmodel();
ko.applyBindings(masterVM, document.getElementById("container1"));
}
if ($.isEmptyObject(secondVM)) {
secondVM= new SecondViewmodel();
ko.applyBindings(secondVM, document.getElementById("container2"));
//Here we are registering a new view model for container2 div
}
});
SecondVeiwModel.js
function SecondViewmodel()
{
var self = this;
self.SetJasonData = function(data){
//Do what ever you want to do with jason data here
ko.utils.arrayForEach(data, function(itemData) {
self.myItems.push(new item (
itemData.ID ,
itemData.LogicalName ,
itemData.Name ,
itemData.ColumnValue
));
});
}
}
希望这能帮助你解决你的问题。
相关文章:
- 无法使用变量访问数据 JSON
- 使用 ng-repeat解析不均匀数据/ json对象
- 在没有jsonp的情况下从另一个域获取数据(json格式)
- 如何获取带参数的数据json
- 如何在android中显示实时雅虎金融股票数据..json格式如下所示
- 使用 JavaScript 将数据 json 显示到网页中
- 高位图表来源于API数据(JSON)
- 使用动态数据json初始化同位素
- Django:将数据JSON从视图传递给javascript
- 存储配置数据 (json)
- 未捕获的SyntaxError:意外的标识符图像数据json
- 接收数据json/jquery
- Jquery数据表数据json
- 不能在cakephp中使用数组数据json
- 在不锁定浏览器的情况下,将大数据JSON从REST请求反序列化为对象
- 如何读取数据JSON格式数组的字符串数据
- 我有一个流星应用程序,需要从/public/_assets/results/mmresults读取数据.Json文件,在
- 数据json不显示在html
- 使用2个下拉列表创建2个并排的表行来比较数据- JSON
- 需要将复杂的json对象转换为合适的angularjs UI树数据json结构