2012-04-21 5 views
1

의 설정 값 나는이보기에 대한 코드가얻고 텍스트 필드

{{#view App.TodoView}}  
    {{view labelView}}  
    {{#view Em.Button target="parentView" action="createNew"}}Add{{/view}}  
{{/view}} 

을 그리고 난 다음 오류 얻을 : 내가 원하는

Uncaught TypeError: Object (subclass of Ember.TextField) has no method 'get' 

을 insertNewLine 메소드도 사용하기 때문에 템플릿에 Em.TextField의 값을 설정할 수 있습니다.

답변

4

문제는 클래스를 정의하고이 클래스에서 value을 얻으려고하는 것입니다. 당신이 원하는 것은 구체적 인스턴스의 value을 얻는 것입니다. 이것은 다음이 경우 todoLabel에서 App.TodoView 검색 될 수있는 값으로 LabelViewvalue을 결합함으로써 달성 될 수 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')이어야하며 이 아니어야합니다.


이제 insertNewlinecancel 같은 추가 방법을 구현할 수 있습니다 - 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); 
    } 
});​ 
+0

들으 많은, 좋은 대답을! 내 질문이있을 수 있습니다 어리석은하지만 ember 워드 프로세서는 가난한 가난한 사람입니다. 그들이 그것을 향상 시키길 바란다. – bravedick

+0

기꺼이 도와 드리겠습니다. 문서가 지속적으로 개선되었습니다. 그 때까지 SO는 도움을 줄 수있는 좋은 자료입니다. – pangratz