我已经调用了webapi并获得了json数据
{
"orderId": 26,
"userId": "53cf1e15",
"user": {
"editablePropertyNames": [],
"email": "rajesh@tech.com",
"firstName": "Rajesh",
"id": "53cf1e15",
"identities": [],
"lastName": "kumar",
"missingProperties": [],
"phoneNumber": "45877298"
},
"locationId": 4024,
"pickupType": 1,
"pickupTimeUtc": "2015-11-27T17:33:00.417"
},
{
"orderId": 601,
"userId": "06bf5983",
"user": {
"editablePropertyNames": [],
"email": "rtest@wa.com",
"firstName": "Rakesh",
"id": "06bf5983",
"identities": [],
"lastName": "Pkumar",
"missingProperties": [],
},
"locationId": 424,
"pickupType": 1,
"pickupTimeUtc": "2016-11-16T21:30:00",
"total": 4.32,
"tax": 0.83
}
var PickupMethodEnum = _enum({
DineIn: 1, DriveThru: 2, TakeOut: 3
})
的index.html
我有5列
#imageIndicator Name PickupName Total scheduledTime
car.png Kumar 1 4.32 2015-11-27T17:33:00.417
我的问题是
我想显示值而不是" 1"在pickupName列中。 (DineIn:1,DriveThru:2,TakeOut:3)。
在#imageindica列中显示图片,如果pickupName =" DriveThru"否则隐藏图像。
以自定义格式显示scheduledTime
如果pickupName =" TakeOut"然后将该行背景颜色更改为灰色,然后在2分钟后删除该行。
答案 0 :(得分:0)
我想在pickupName列中显示值而不是“1”。 (DineIn: 1, DriveThru: 2, TakeOut: 3
)。
Object.keys( objectName )[ propertyIndex ]
将返回所需属性的名称
一旦获得JSON数据,就可以使用条件语句解决其余问题。你没有提供你的尝试,因此没有多少工作。
答案 1 :(得分:0)
首先,您需要正确地enum
numbers:"String"
,因为您从JSON
获得了数字。
//Global Object
var pickupNameEnum = {
0: "DineIn",
1: "DriveThru",
2: "TakeOut"
};
在浏览showRow(singleRowObject)
JSON
的函数
function showRow(singleRowObject){
var imageString="";
var hideImage=false;
var showString='';
var retutnObject={};
if(pickupNameEnum[singleRowObject.pickupType]!=undefiend){
showString='DineIn';
//DineIn
}else if(singleRowObject.pickupType==){
//DriveThru
showString='DriveThru';
imageString="<img src='abc.png' alt='img'></img>";
}else if(singleRowObject.pickupType==){
//TakeOut and change Color on basis of this flag
hideImage=true;
showString='TakeOut ';
}
retutnObject.hideImage=hideImage;
retutnObject.imageString=imageString;
retutnObject.showString=showString;
}
对于日期拆分dateString并参考此question
要删除行更改,请参阅this