0

I am a beginner to Emberjs and please go through the code and please guide me where am I wrong.

.js file

Sample = Ember.Application.create();


Sample.Router.map(function(){
    this.route('view');
    this.resource('add');
})
Add = Ember.Object.extend();
View = Ember.Object.extend();

Sample.AddNewRoute = Ember.Route.extend({
    model:function(){
        return Sample.Add.createRecord();
    }
});

Sample.ViewController = Ember.ArrayController.extend();
Sample.AddController = Ember.ObjectController.extend({
    content:[],
    save:function(){
        this.get("model.transaction");
        this.get("target").trasitionTo('view');
    }
});

Sample.ViewController = Ember.ArrayController.extend();

Sample.Store = DS.Store.extend({
    revision:11,
    adapter: DS.LSAdapter.create(),
});

Sample.Add =  DS.Model.extend({
  name: DS.attr("string"),
  desig: DS.attr("string"),
  age: DS.attr("integer")
});

.html file

<!DOCTYPE html>
<html>
<head>
 <script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/handlebars-1.0.0.js"></script>
        <script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/ember-1.0.0.js"></script>
        <script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/ember-data.js"></script>
        <script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/libs/localstorage_adapter.js"></script>
        <script type="text/javascript" src="C:/Users/Guest/Downloads/ember/starter-kit-1.0.0/js/sample.js"></script>

<meta charset=utf-8 />
<title>Demo application</title>
</head>
<body>

  <script type="text/x-handlebars">
  <h1>Welcome to Demo!</h1>
  {{#link-to 'add'}}Add Member{{/link-to}}
  {{#link-to 'view'}}View Members{{/link-to}}
  {{outlet}}
  </script>

   <script type="text/x-handlebars" data-template-name ='add'>

  <h1>Add member!</h1>  
  <form {{action 'save' on='submit'}}>

  <br>{{#view Ember.TextField valueBinding="name" placeholder= "Enter the name"}}{{/view}}</br>
  <br>{{#view Ember.TextField valueBinding="desig" placeholder= "Enter the designation"}}{{/view}}</br>
  <br>{{#view Ember.TextField valueBinding="age" placeholder= "Enter the age"}}{{/view}}</br>
  <br><button {{action "save"}}>Add Member</button></br>   

  </form>  

  </script>

   <script type="text/x-handlebars" data-template-name ='view'>
   <h3><strong>All Registered Members!</strong>
   <br></br>
   {{#each controller}}

   <br>{{name}}</br>
   <br>{{desig}}</br>
   <br>{{age}}</br>
   {{else}}
   No members registered yet! :(

   {{/each}}

   </script>

    enter code here

</body>
</html>

After I click the 'Add Member button I am getting the following error:

Uncaught TypeError: Object [object Object] has no method 'trasitionTo'

4

1 回答 1

0

您有一条记录 Add 用于处理点击。您可以将添加记录重命名为其他名称吗?

Add = Ember.Object.extend();//use someother name instead of Add

而是将其命名为其他名称,例如 MyAddRecord 或其他名称。一旦你这样做,你应该会得到正确或相关的错误消息。

于 2013-10-25T14:33:15.947 回答