3
Concider包含單選按鈕和標籤的jQuery Mobile「list」。
<!-- ko foreach: $data.answers -->
<input type="radio" name="radio-choice" data-bind="attr: { id: [...] }" />
<label data-bind="attr:{ for: [...] }">Label</label>
<!-- /ko -->
爲了工作,爲屬性的標籤的需要是相同的作爲輸入的ID。
REPLACEMENT FOR [...] RESULTS IN
$index ok
'radio-nr-'+$index fails
$root.testFunction(1) ok
$root.testFunction($index) fails
'radio-nr-'.concat(1) ok
'radio-nr-'.concat($index) fails
其中
function testFunction(a) { return "radio-nr-"+a; };
爲什麼我的串接$索引失敗所有嘗試?
謝謝!
重複http://stackoverflow.com/questions/11302338/knockout-is-not-evaluating-an-expression-when-using-index-in-a-binding –