新增Angular和javascript,並且一直困擾着我的大腦2天。我有一個HTML表格,我需要顯示和隱藏複選框。每行有5個複選框。什麼將可見取決於FieldName的數組中的FieldName和索引。我已經評論了下面的代碼,我希望它能解釋我所嘗試過的。根據數組中的值顯示/隱藏複選框
HTML頁面上的角代碼看起來是這樣的,具有範圍從0到4的數。 - 納克放映=「ShowCheckbox(info.FieldName,0)」
JavaScript的樣子 - -
$scope.ShowCheckbox = function (FieldName, index) {
// FieldName is "MandatedMaterials", "AgencyAgmt", etc.
var MandatedMaterials = [true, true, false, false, false];
var AgencyAgmt = [true, true, false, false, false];
return FieldName[index];
// This is what I really really want to work.
// Only MandatedMaterials[2] and AgencyAgmt[3] return false
// My experiments to narrow down the problem.
//if (FieldName == "MandatedMaterials")
// works, so FieldName is coming from index.cshtml
//if (index == 3)
// works, same thing as above
//if (MandatedMaterials[0] == true)
// works, in that it showed all checkboxes
//if (AgencyAgmt[0] == true)
// works, same as above
//if (FieldName[0] == true)
// NOPE -- should show all checkboxes, but instead none
//if (FieldName[0])
// works, in that it shows all checkboxes
// For testing purposes I had "if" code to return true or false for the
// commented out statements above. This meant those bits of code would
// show all the checkboxes.
}
如果您可以幫助我獲得顯示和隱藏的相應複選框,我將非常感激。謝謝。
你能展示一段HTML代碼嗎? – 2015-02-08 23:43:13