2013-11-01 23 views
0

我有應該有一個簡單的解決方案的問題。出於某種原因,我的行動助手沒有連接到它的方法。灰燼動作沒有連接到方法

這裏是我的JSBin http://jsbin.com/UMaJaM/5/edit

代碼複製下面以供參考。

HTML:

<!DOCTYPE html> 
<html> 
<head> 
<meta name="description" content="Ember template" /> 
<meta charset=utf-8 /> 
<title>JS Bin</title> 
    <script src="http://code.jquery.com/jquery-1.9.0.js"></script> 
    <script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script> 
    <script src="http://builds.emberjs.com/tags/v1.1.2/ember.js"></script> 
</head> 
<body> 
    <div id="main"></div> 
</body> 
</html> 

的JavaScript:

var TemplatedViewController = Ember.Object.extend({ 
    templateFunction: null, 
    context: null, 
    viewBaseClass: Ember.View, 
    view: function() { 
     var controller = this; 
     var context = this.get('context') || {}; 
     var args = { 
      template: controller.get('templateFunction'), 
      controller: controller 
     }; 
     args = $.extend(context, args); 
     return this.get('viewBaseClass').extend(args); 
    }.property('templateFunction'), 
    appendView: function (selector) { 
     this.get('view').create().appendTo(selector); 
    }, 
    appendViewToBody: function (property) { 
     this.get(property).create().append(); 
    } 
}); 

var template_source = '<button type="button" class="btn" {{action "button"}}>Click</button>'; 

var MyController = TemplatedViewController.extend({ 
    templateFunction: Ember.Handlebars.compile(template_source), 
    button: function() { 
     console.log('hello world'); 
    } 
}); 

var controller = MyController.create(); 

$(function() { 
    controller.appendView('#main'); 
}); 

回答

1

您需要創建一個應用程序灰燼。添加到您的腳本的開頭:

App = Ember.Application.create();