0
ContainerView
에 동적으로 Component
을 추가하는 데 문제가 있습니다. 이 jsfiddle를 참조하십시오컨테이너 레이아웃에 렌더링되지 않은 구성 요소 레이아웃
http://jsfiddle.net/theazureshadow/7n2hz/
구성 요소 루트 요소는 컨테이너에 배치되어 있지만, 구성 요소와 관련된 레이아웃이 렌더링되지 않습니다. 나는 template
속성을 주석 처리를 제거하면
App = Ember.Application.create({});
App.IndexRoute = Ember.Route.extend({});
App.IndexView = Ember.View.extend({
didInsertElement: function() {
console.log('IndexView inserted');
var container = this.get('container');
container.pushObject(Ember.TextField.create());
container.pushObject(App.MyComponent.create());
}
});
App.MyContainer = Ember.ContainerView.extend({
didInsertElement: function() {
console.log('MyContainer inserted');
}
});
App.MyComponent = Ember.Component.extend({
classNames: ['my-component'],
//template: Ember.Handlebars.compile('<p>Compiled directly</p>'),
didInsertElement: function() {
console.log('MyComponent inserted');
}
});
는 제대로 그 내용을 렌더링한다. 또한 인덱스 뷰에 직접 구성 요소를 삽입하여 올바르게 렌더링합니다 (이 경우 classNames가 추가되지는 않지만).
<script type="text/x-handlebars" data-template-name="application">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Render component directly:</h2>
{{my-component}}
<hr/>
<h2>Add component to container:</h2>
{{view App.MyContainer viewName="container"}}
</script>
<script type="text/x-handlebars" data-template-name="components/my-component">
<b>My component</b>
</script>
나는 Ember.run
와 장난 시도했지만 운이 지금까지했습니다. pushObject
에 대한 잘못된 후크 didInsertElement
이 있습니까?
이것은 나를 위해 작동하지 않습니다. 나에게 일하는 jsfiddle을 보여줄 수 있니? 'my-component' ('My component'대신'compile'에 전달 된 문자열의 텍스트)이 템플릿에 정의되어 있습니다. 템플릿이 다른 언어로 렌더링되는 것에 놀랐습니다. ContainerView 일반적인보기보다 – theazureshadow
내 대답이 조금 바뀌 었습니다. 작업 예제는 다음과 같습니다. http://jsfiddle.net/7n2hz/6/ – Oliver
감사합니다! 구성 요소의 배치가 레이아웃에 자동 바운드? – theazureshadow