2017-11-09 9 views
-1

이 질문은 어리석은 경우 미리 사과드립니다. 나는 PHP 권한에 대한 검사를 실행하려고하고 있으며 다시 false로 돌아 오면 Knockout에서 비활성화 된 체크 박스를 만들거나 클래스에 "disabled"를 추가합니다. 그러나 운이별로 없다. 내 코드. 감사합니다녹아웃의 체크 박스에 사용할 수없는 클래스 추가하기

ax.ko.UserProfileModel = function(data) { 
    this.display_name = data.display_name; 
    this.enabled = data.enabled; 
    this.first_name = data.first_name; 
    this.gender = data.gender; 
    this.sales_rep_code = data.sales_rep_code; 
    this.billable = data.billable; 
} 


//VM 
ax.ko.UserProfilesVM = function(data) { 
var self = this; 

self.userProfile = ko.observableArray([]); 
self.userProfiles = ko.observableArray([]); 
self.isLoading = ko.observable(false); 
self.viewCreateEdit = ko.observable(''); 
self.carouselSettings = ax.Carousel.defaults; 
self.canEditAccount = ko.observable(); 
self.isBillable = ko.observable(); 

self.populateUserProfiles = function(data) { 
self.userProfiles($.map(data,function(i) { return new 
ax.ko.UserProfileModel(i); })); 
}; 

self.populateUserProfile = function(data) { 
self.userProfile(new ax.ko.UserProfileModel(data)); 
}; 
}; 


<? if ($perms['user_profiles|edit_billable']===FALSE) { ?> 
     <div class="field"> 
     <label><?=l(273)?></label> 
     <div class="input"> 
      <input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, disable:isBillable();"> 
     </div> 
     </div> 
    </div> 

<? } ?> 
+2

당신이 "가능"또는 "사용 안 함"시도 되세요 제본? http://knockoutjs.com/documentation/enable-binding.html –

+0

나는 그것을 시도 할 것이다, 나는 그것에 대해 읽었지만 다른 사람들의 코드를 통해 작업하고 있기 때문에 어떻게 구현해야 하는지를보고 있었다. 고마워요. – erics15

+0

감사합니다. @JasonSpake - 아무 소용이 없었습니다. :/ – erics15

답변

2

는 @ 제이슨에 의해 제안 당신이 당신의 바인딩 http://knockoutjs.com/documentation/disable-binding.html에 해제 추가 할 수 있습니다 더처럼,이 시도 :

MyVM = function(condition){ 
 
    that = this; 
 
    that.flag = ko.observable(true); 
 
    that.condition = ko.observable(condition); 
 
} 
 

 
ko.applyBindings(new MyVM(true));
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> 
 

 

 
<div> 
 

 
<input type="checkbox" data-bind="checked: flag, disable: condition"/> 
 

 
</div>