문제는 클래스를 정의하고이 클래스에서 value
을 얻으려고하는 것입니다. 당신이 원하는 것은 구체적 인스턴스의 value
을 얻는 것입니다. 이것은 다음이 경우 todoLabel
에서 App.TodoView
검색 될 수있는 값으로 LabelView
의 value
을 결합함으로써 달성 될 수 http://jsfiddle.net/pangratz666/PTPsV/ 참조 :
핸들 바을 :
{{#view App.TodoView }}
<!-- Bind the value of the LabelView to todoLabel on the App.TodoView -->
{{view LabelView valueBinding="todoLabel" }}
{{#view Em.Button target="parentView" action="createNew" }}Add{{/view}}
{{/view}}
스크립트을 :
App.TodoView = Em.View.extend({
LabelView: Em.TextField.extend(),
createNew: function(){
var value = this.get('todoLabel');
console.log('le todoLabel', value);
}
});
cl 엉덩이 LabelView
그것은 대문자로 작성하는 것이 관습이지만 인스턴스는 lowerCase로 작성됩니다. 명명 규칙에 대한 좋은 블로그 게시물 The Emberist을 참조하십시오.
또한 Ember.Object
의 속성에 액세스하려면 get
이어야하며 this.get('todoLabel')
이어야하며 이 아니어야합니다.
이제 insertNewline
및 cancel
같은 추가 방법을 구현할 수 있습니다 - text_support 참조가, insertNewline
하지 insertNewLine
의주의.
결과는 같을 것이다
, http://jsfiddle.net/pangratz666/9ZLAC/ 참조 :
App.TodoView = Em.View.extend({
LabelView: Em.TextField.extend({
insertNewline: function(){
this.get('parentView').createNew();
},
cancel: function(){
this.set('value', '');
}
}),
createNew: function(){
var value = this.get('todoLabel');
console.log('le todoLabel', value);
}
});
들으 많은, 좋은 대답을! 내 질문이있을 수 있습니다 어리석은하지만 ember 워드 프로세서는 가난한 가난한 사람입니다. 그들이 그것을 향상 시키길 바란다. – bravedick
기꺼이 도와 드리겠습니다. 문서가 지속적으로 개선되었습니다. 그 때까지 SO는 도움을 줄 수있는 좋은 자료입니다. – pangratz