我有这样的json响应来自API调用。
last_row = GetLastRow(Sheet1, 1)
现在我正在检索我在选择器中显示的`{
"id": "7",
"issue_title": "Apr - May 2015",
"issue_no": "Issue 1.4",
"cover_image_url": "http://www.link.org/apr--may-2015-7.jpg",
"synopsis_pdf_url": "",
"advertisers_pdf_url": "",
"issue_date": "01-04-2015",
"issue_year": "2015"
},
{
"id": "3",
"issue_title": "Feb-Mar 2015",
"issue_no": "Issue 1.3",
"cover_image_url": "http://www.link.org/febmar-2015-3.jpg",
"synopsis_pdf_url": "http://www.link.org/febmar-2015-3.pdf",
"advertisers_pdf_url": "http://www.link.org/febmar-2015-3.pdf",
"issue_date": "01-02-2015",
"issue_year": "2015"
},
{
"id": "2",
"issue_title": "Dec 2014 - Jan 2015",
"issue_no": "Issue 1.2",
"cover_image_url": "http://www.link.org/dec-2014--jan-2015-2.jpg",
"synopsis_pdf_url": "",
"advertisers_pdf_url": "",
"issue_date": "01-12-2014",
"issue_year": "2014"
},
{
"id": "1",
"issue_title": "Oct - Nov 2014",
"issue_no": "Issue 1.1",
"cover_image_url": "http://www.link.org/oct--nov-2014-1.jpg",
"synopsis_pdf_url": "",
"advertisers_pdf_url": "",
"issue_date": "01-10-2014",
"issue_year": "2014"
}`
。
我想如果用户点击issue_year
,则表格数据应仅显示具有相同issue_year
的记录。
就像从选择器点击2014一样,它应该只显示第3和第4条记录。
现在来自控制器我正在准备选择器数据时在选择器中传递jsonResponse [i]的对象,以便在其点击中检索相同但我得到issue_year
。
js代码如下
undefined
xml文件
function openpastIssues(e) {
var url = "http://example.com/api/past_year_issue.aspx";
var jsonResponse;
var response;
var data = [];
var pickerData = [];
var singleData = [];
var row;
var xhr = Ti.Network.createHTTPClient({
onload : function() {
// parse the retrieved data, turning it into a JavaScript object
Ti.API.info("From Past Issues (function): " + this.responseText);
jsonResponse = JSON.parse(this.responseText);
var rowHeight = 150;
// just pick the right height here
var imageRowIsFull = false;
var myImage;
var issuelbl;
var row = Ti.UI.createTableViewRow({
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
layout : "horizontal"
});
for (var i = 0; i < jsonResponse.length; i++) {
var tView = Ti.UI.createView({
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
left : "5%",
right : "5%",
top : "5",
bottom : "5",
backgroundColor : "#A9F5A9",
//backgroundColor : "black",
layout : "vertical"
});
issuelbl = Ti.UI.createLabel({
color : 'blue',
text : jsonResponse[i].issue_title,
height : "auto",
width : "auto",
left : "3%",
font : {
fontSize : 13
},
});
tView.add(issuelbl);
myImage = Ti.UI.createImageView({
width : 120,
//left : "5%",
//right : "5%",
top : "5",
//bottom:"5",
height : 150,
image : jsonResponse[i].cover_image_url,
obj : jsonResponse[i]
});
tView.add(myImage);
try {
myImage.addEventListener('click', function(e) {
Ti.API.info('Clicked data = ' + JSON.stringify(e.source.obj));
var jsonRes = e.source.obj;
Alloy.createController('singleissue', jsonRes);
});
} catch(e) {
}
row.add(tView);
//row.add(myImage);
imageRowIsFull = false;
if ((i + 1) % 2 == 0) {//this will add a new row every 2 items.
imageRowIsFull = true;
data.push(row);
row = Ti.UI.createTableViewRow({
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
layout : "horizontal",
filterCriteria :jsonResponse[i].issue_year
});
}
pickerData[i] = Ti.UI.createPickerRow({
title : jsonResponse[i].issue_year,
obj : jsonResponse[i]
});
}
if (!imageRowIsFull) {//do not forget to add the last row
data.push(row);
}
//table.setData(data);
$.issueTable.setData(data);
$.picker.add(pickerData);
},
onerror : function(e) {
Ti.API.debug(e.error);
alert('error');
},
timeout : 5000
});
xhr.open("GET", url);
xhr.send();
}
$.picker.addEventListener('change', function(e) {
Ti.API.info('From picker ' + e.source.obj);
});
基本上我想显示从选择器中选择的特定年份的记录。
任何人都可以请帮助。 我花了很多时间在这上面。
答案 0 :(得分:0)
您可以制作NSMUtableArray并根据“issue_year”的值重新填充它。您可以使用NSPredicate对json进行排序