문자열을 제공 할 때 도트 표기법을 사용하는 방법은 무엇입니까?jshint 솔루션 "도트 표기법으로 작성하는 것이 더 낫습니다."도트가 아닌 표기법을 사용할 때
각형의 'x 편집 가능한'컨트롤 유형을 채우기 위해 일부 코드를 작성했습니다. 내 webapi 서비스가 나에게 전달할 문자열 식별자를 기반으로 사전 정의 된 값 배열을 가지고 있습니다. 문자열을 돌려 보냅니다. 그것은 나를 점 표기법을 사용하고 싶어하기 때문에
valuetoshow = myarray['stringFromWebApiCall'];
JSHINT는 적합을 던지고있다 :이 문자열을 기반으로, 나는 다음과 같은 방법을 사용하여 미리 정의 된 배열에서 객체를 선택합니다. JSHINT가 나에게 말하는 이유를 이해하고 어떤 줄을 쓰는지 이해한다. 코드를 "answers.undergraduate = bigarray"와 같이 변경하면 jshint가 수정 될 것이다. 아래 코드에서 문자열을 제공 할 때 .notation을 사용하여 배열에 액세스하는 방법을 알지 못합니다.
문자열을 사용하여 점 표기법을 찾는 자바 스크립트에서 일종의 메소드가 있습니까? 나는 C#에 익숙하다.이 준 타입의 변수를 정의하는 것은 내 머리를 감싸는 것이 힘들다는 것을 증명한다.
['UNDERGRADUATE'] is better written in dot notation.
내가 오류를 억제하려고 시도해야
['MASTERS'] is better written in dot notation.
['UNDEFINED'] is better written in dot notation.
['GRADUATE'] is better written in dot notation.
['HONORARY'] is better written in dot notation.
['DOCTORATE'] is better written in dot notation.
여기에 실제 코드
answers['UNDERGRADUATE'] = [
{ 'name': 'Find a job', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Create a network with STTI members', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Receive nursing guidance', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Learn and grow through online continuing nursing education', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false }
];
answers['GRADUATE'] = [
{ 'name': 'Find a job', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Expand your network with STTI members', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Grow your portfolio', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Develop advanced leadership skills', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Stay current on nursing trends', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Learn and grow through online continuing nursing education', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false }
];
answers['NURSE LEADER'] = [
{ 'name': 'Find a job', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Expand your network with STTI members', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Grow your portfolio', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Develop advanced leadership skills', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Stay current on nursing trends', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Learn and grow through online continuing nursing education', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false }
];
answers['HONORARY'] = [
{ 'name': 'Find a job', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Expand your network with STTI members', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Grow your portfolio', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Develop advanced leadership skills', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Stay current on nursing trends', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Learn and grow through online continuing nursing education', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false }
];
answers['DOCTORATE'] = [
{ 'name': 'Find a job', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Expand your network with STTI members', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Grow your portfolio', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Develop advanced leadership skills', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Stay current on nursing trends', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Learn and grow through online continuing nursing education', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false }
];
answers['MASTERS'] = [
{ 'name': 'Find a job', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Expand your network with STTI members', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Grow your portfolio', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Develop advanced leadership skills', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Stay current on nursing trends', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Learn and grow through online continuing nursing education', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false }
];
answers['UNDEFINED'] = [
{ 'name': 'Find a job', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Expand your network with STTI members', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Grow your portfolio', 'ticked': false, 'hideThisGroup':false, 'checkboxDisabled': false },
{ 'name': 'Develop advanced leadership skills', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Stay current on nursing trends', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false },
{ 'name': 'Learn and grow through online continuing nursing education', 'ticked': false, 'hideThisGroup':true, 'checkboxDisabled': false }
];
if ($rootScope.constituent != undefined){
if ($rootScope.constituent.InductedAs != undefined) {
$scope.constituentPriorities = answers[$rootScope.constituent.InductedAs.toUpperCase()];
} else {
$scope.constituentPriorities = answers['UNDEFINED'];
}
}
개체에 속성이 있는지 확인하십시오. http://stackoverflow.com/questions/135448/how-do-i-check-if-an-object-has-a-property-in-javascript – Hobbs
음 ...대괄호 표기법이 필요한 코드의 유일한 속성 이름은'NURSE LEADER'이며 점 표기법으로 다른 모든 것을 쓸 수 있습니다. – Teemu
괄호 안에 _stimings_primitives_가 없습니다. 그것들은 하드 코드되어 동적으로 생성되지 않습니다. 괄호 안에 변수가 필요한 경우 따옴표를 제거하십시오. '$, _, AZ, az, 0-9' 이외의 문자를 포함하는 속성 이름은 _hardcoded_, – Teemu