我在jaydata中有如下数据模型
Model.js
$data.Entity.extend('Expense', {
Id: { type: 'int', key: true, computed: true },
Name: { type: 'string' },
Date: { type: Date },
Price: { type: 'number' }
});
$data.Entity.extend('Regular', {
Id: { type: 'int', key: true, computed: true },
Name: { type: 'string' },
Price: { type: 'number' }
});
$data.EntityContext.extend("ExpenseDatabase", {
Expenses: { type: $data.EntitySet, elementType: Expense },
Regulars: { type: $data.EntitySet, elementType: Regular }
});
我想通过Date提交结果,这是我无法做到的。有人可以帮我这方面吗?我的过滤代码如下。但它不起作用,会引发类型错误。
var d = new Date();
exDB.Expenses
.filter( function(exp) {
return exp.Date.day() == d.getDate();
})
.forEach( function(exp) {
alert(exp.Name + exp.Date.getDate());
toAdd = '<li><a>'+exp.Name+'<span class="ui-li-count">'+exp.Price+'</span></a></li>';
$("#expenseList").append(toAdd);
$("#expenseList").listview("refresh");
});
答案 0 :(得分:0)
通用解决方案是编写一个查询,其中包含两个检查间隔的条件:
//first second of the current day
var intervalStart = new Date(new Date(date - date % (24 * 60 * 60 * 1000)));
//last second of the current day
var intervalEnd = new Date(intevalStart .valueOf() + 24 * 60 * 60 * 1000);
exDB.Expenses
.filter( function(exp) {
return exp.Date >= this.minDate && exp.Date <= this.maxDate
}, {minDate: intervalStart , maxDate: intervalEnd })
.foreach(function(){...});