JSFiddles에서 부트 스트랩 테이블을 테스트하는 동안 테이블 안의 버튼을 클릭하면 버튼이 사라지고 일반 텍스트로 바뀌도록하려고했습니다. .empty()를 사용한 후에 DOM 요소에 HTML을 삽입 할 수없는 이유는 무엇입니까?
<tbody>
<tr>
<td>John Doe</td>
<td>[email protected]</td>
<td><button class="disabled" data-bind="click: dosomething.bind($data, 'was', 'sup')" type="button" class="btn btn-warning">Crear Cuenta</button></td>
</tr>
</tbody>
그래서 버튼을 클릭하면에 이벤트를 바인딩 KnockoutJS를 사용하여
, 나는 다음과 같은 한 : 다음은 마크 업의 관련 부분입니다function ViewModel() {
var self = this;
self.dosomething = function (data, event, param1, param2) {
var $stuff = $(param2.target).prop("disabled",true);
var $stuff2 = $(param2.target).hasClass("disabled");
var $stuff3 = $(param2.target).parent();
$(param2.target).parent().empty();
$(param2.target).parent().html("hello");
}
self.donext = function(){
var $stuff = $(".disabled").prop("disabled",false);
}
}
var app = new ViewModel();
ko.applyBindings(app);
그러나이 hello
은 렌더링 할 것 모든. 하지만 $(param2.target).parent().empty();
행을 삭제하면 버튼이 원래 내가 원하는대로 hello
으로 대체됩니다. .empty()
만 자식 콘텐츠 만 제거하면 왜 나중에 html 콘텐츠를 추가 할 수 없습니까?
이것은 'foreach'바인딩 안에 있습니까? KO의 UI에서 항목을 비활성화하거나 제거하는 더 쉬운 방법이 있습니다. 이와 같은 jquery를 사용하여 물건을 제거하면 바람직하지 않은 동작이 발생합니다. – adiga
@adiga 실제로 예. 문제는 이미 해결되었지만 언급 한 UI에서 항목을 제거하는 더 좋은 방법에 관심이 있습니다. 이 방법에 대해 더 많이 알 수 있습니까? – CodeIntern