以下代碼中的「\」是什麼意思?ng是什麼意思?
<div ng-style="{ \'cursor\': row.cursor }"
爲什麼不能一個只寫
<div ng-style="{ cursor: row.cursor }"
完整的代碼
rowTemplate: '<div ng-style="{ \'cursor\': row.cursor }" ng-repeat="col
in renderedColumns" ng-class="col.colIndex()" class="ngCell {{col.cellClass}}"
style="overflow: visible"><div class="ngVerticalBar" ng-style="{height: rowHeight}"
ng-class="{ ngVerticalBarVisible: !$last }"> </div><div ng-cell></div></div>',
我也逼債明白爲什麼在第一NG-風格的代碼使用\」,並在第二個ng-style代碼直接使用高度而不是\'。從https://github.com/angular-ui/ng-grid/issues/994
'\'是一個轉義字符。但是由於你似乎在字符串周圍使用了雙引號,這似乎是多餘的。這個:'「{\'cursor \':row.cursor}」'與此相同:'「{'cursor':row.cursor}」'。但是,如果您在外部也使用單引號,那麼您必須轉義內部單引號才能防止字符串結束,類似於:''{\'cursor \':row.cursor}'' – Nope
完整的代碼本來可以很方便地看到前面的例子,因爲最初的例子使單引號的轉義看起來毫無意義。但是現在問題中的完整字符串可以看到最外面的引號是單引號,因此內部單引號必須轉義或者它們會破壞字符串。 – Nope
最後添加主要點? :)轉義字符在那裏可以安全地解析匹配單引號內的內容。你可以簡單地將它們替換爲光標的雙引號,並且將是相同的東西 – XGreen