问号在以下代码段中的作用是什么:
Template.lists.selected = function () { return Session.equals('list_id', this._id) ? 'selected' : ''; };
EmmyS.. 6
它被称为多种语言的三元运算符.这是完整if-then
语句的捷径.
而不是写这个:
Template.lists.selected = function () { if(Session.equals('list_id', this._id)) { return 'selected'; } else { return ''; } };
你做这个:
Template.lists.selected = function () { return Session.equals('list_id', this._id) ? 'selected' : ''; };
该if
立即返回是问号; 该else
回报是冒号后面.
它被称为多种语言的三元运算符.这是完整if-then
语句的捷径.
而不是写这个:
Template.lists.selected = function () { if(Session.equals('list_id', this._id)) { return 'selected'; } else { return ''; } };
你做这个:
Template.lists.selected = function () { return Session.equals('list_id', this._id) ? 'selected' : ''; };
该if
立即返回是问号; 该else
回报是冒号后面.