未經測試!
概述:爲除第一個名字以外的所有名稱添加前綴「,」。
模板:
{{#beatles}}
{{name}}
{{/beatles}}
初始化:
window.app.first_flag = true; // initialize
// assumes that the app has created the window.app object/hash to
// hold the app's data
查看:
{
"beatles": [
{ "firstName": "John", "lastName": "Lennon" },
{ "firstName": "Paul", "lastName": "McCartney" },
{ "firstName": "George", "lastName": "Harrison" },
{ "firstName": "Ringo", "lastName": "Starr" }
],
"name": function() {
var n = this.firstName + " " + this.lastName,
prefix = ", ";
if (window.app.first_flag) {
window.app.first_flag = false;
prefix = "";
}
return prefix + n;
}
}
在我的數組,我沒有一個對象,而是一個字符串。我不能做'this.firstname'我該如何引用他們? – Joseph 2012-02-17 05:46:48
嘗試使用只是'這個' – 2012-02-17 16:27:06
最終放棄了這個想法。感謝您的幫助。 – Joseph 2012-02-21 10:19:24