我是编程的新手,我正在尝试使用Javascript编写待办事项列表并尝试使用JQuery。我在网上找到了一个删除线的动画,我想在列表中实现,但我不太清楚这两行代码是做什么的,并且想知道是否有人可以为我详细说明,以便我能更好地理解?删除线功能如下:
@Data
@NoArgsConstructor
@Entity
@Immutable
@Table(name = "MY_ORDER", schema = "Data")
public class MyOrder implements Serializable {
@Id
@Column(name = "ORD_ID")
private Integer orderId;
@NonNull
@Column(name = "APP_NAME")
private String appName;
@NonNull
@Column(name = "ORD_NUM")
private String orderNumber;
@ManyToOne
@JoinColumn(name = "STO_ID")
private Store store;
@OneToOne
@JoinColumns({
@JoinColumn(name = "APP_NAME", referencedColumnName = "APP_NAME", insertable = false, updatable = false),
@JoinColumn(name = "ORD_NUM", referencedColumnName = "ORD_NUM", insertable = false, updatable = false)})
@org.hibernate.annotations.ForeignKey(name = "none")
private Tender tender;
@OneToMany
@JoinTable(
name = "TX_to_MY_ORDER", schema = "Data",
joinColumns = { // note X_to_MY_ORDER.ORD_NO vs. ORD_NUM
@JoinColumn(name = "APP_NAM", referencedColumnName = "APP_NAM", insertable = false, updatable = false),
@JoinColumn(name = "ORD_NO", referencedColumnName = "ORD_NUM", insertable = false, updatable = false)},
inverseJoinColumns = {@JoinColumn(name = "TRN_NO", insertable = false, updatable = false)})
@org.hibernate.annotations.ForeignKey(name = "none")
private Set<Transaction> transactions;
/**
* Because APP_NAM and ORD_NUM are not foreign keys to TX_TO_MY_ORDER (and they shouldn't be),
* Hibernate 5.x saves this toString() as the 'owner' key of the transactions collection such that
* it then appears in the transactions collection's own .toString(). Lombok's default generated
* toString() includes this.getTransactions().toString(), which causes an infinite recursive loop.
* @return a string that is unique per order
*/
@Override
public String toString() {
// use appName + orderNumber since, as they are the columns used in the join, they must (?) have
// already been set when attaching the transactions - primary key sometimes isn't set yet.
return this.appName + "\00" + this.orderNumber;
}
}
我困惑的两条线是:
//var _Text sets the _Text to the individual list item
var _text = document.getElementById("item_" + cbId);
$(document).ready(function() {
_text = $(itemText).text();
StrikeThrough(0);
});
//Strikethrough animation function
function StrikeThrough(index) {
if (index >= _text.length)
return false;
var sToStrike = _text.substr(0, index + 1);
var sAfter = (index < (_text.length - 1)) ? _text.substr(index + 1,
_text.length - index) : "";
$(itemText).html("<strike>" + sToStrike + "</strike>" + sAfter);
window.setTimeout(function() {
StrikeThrough(index + 1);
}, 100);
我特别困惑的是这些变量被准确设置为什么
答案 0 :(得分:0)
sToStrike
设置为从当前索引位置的开头到下一个字符的文本
如果索引不是最后一个字符
sAfter
设置字符串的其余部分
答案 1 :(得分:0)
此行将sToStrike
的子字符串从索引_text
分配给0
索引index + 1
:
var sToStrike = _text.substr(0, index + 1);
这一行包含一个三元表达式,它是一个内联if / else。它将sAfter
的子字符串从索引_text
分配给索引index + 1
或空字符串_text.length - index
依赖于""
评估为True或错误,按各自的顺序排列:
index < (_text.length-1)