mercredi 26 août 2015

Selection in first drop down populates data in second dropdown but only on first click, why?

i have created 2 drop downs where selection of first drop down effects the data content of the second drop down, I have achieved this much successfully.howsoever,this functionality is occurring inly on first click instead it should happen every time, probably I am missing out on some minor property. Any help is greatly appreciated. here is a link to jsfiddle :to my working code

and here is a link to jsbin,(i dont know what error it is showing in this even when code is exactly same) :to my code

App = Ember.Application.create();

App.Router.map(function() {
  // put your routes here
});

App.ArticleAdapter= DS.FixtureAdapter.extend({});
App.Article =DS.Model.extend({
        title: DS.attr(),
        body: DS.attr(),
        shouldReloadAll:true,
        comments: DS.hasMany('comment', {async : true})
        //async tells compiler to load data from comment everytime this is rendered
});

App.Comment =DS.Model.extend({
        text: DS.attr(),
        shouldReloadAll:true,
        article: DS.belongsTo('article', { async: true })
});


App.Article.FIXTURES=[ 
                  {
                        id:1,
                        title : 'Ember',
                        body:'Its a great technology but need lot of studying and practice',
                        comments:[1]
                  },{
                        id:2,
                        title : 'Angular',
                        body:'it takes  less understanding but has more coding the ember',
                        comments:[2,3]
                  //this will be an aray coz it is has many relation
                  }
];

App.Comment.FIXTURES=[ 
                      {
                        id:1,
                        text : 'Yyyieee excited to learn ember',
                        aricle: 1
                        //its not an array coz it will be related to single object
                    },{
                        id:2,
                        text : 'I will start Angular once i have fininshed with ember',
                        article: 2
                      },{
                        id:3,
                        text : 'Angular can be interesting',
                        article: 2
                       }
    ];


App.CommentAdapter= DS.FixtureAdapter.extend();


App.IndexController = Ember.ArrayController.extend({
        
        articleValue: null,
        selected: null,
        
        articleStore: Em.computed(function(){
                console.log("data is : " + this.get('articleValue'));
                console.log("data is : " + this.get('selected'));
                 return this.store.findAll("article");
        }).property("selected"),
        
        
        
          availableComment: Em.computed(function () {
        var make = this.get('selected');
        // the line below returns the id and not an object
        console.log(make);
        if (make === undefined || make === null)
            return [];
        return this.get('selected').get('comments');
    }).property('articleValue'),
        
        
        actions:{
                callIndexController: function(){
                        var select= this.get("selected");
                        console.log("hi :" + select);
                }
        }
});

App.IndexRoute = Ember.Route.extend({
          model: function() {
                 return [];
          },
          
        
});
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Ember Starter Kit</title>
</head>
<body>
<script type="text/x-handlebars"> 
    <h2>Welcome to Ember.js</h2>
        {{outlet}}
</script>
  

  
<script type="text/x-handlebars" id="index">
First drop down: 
   {{  
         view "select"
         contentBinding=articleStore
         optionLabelPath="content.title"
         optionValuePath="content.id"
                 prompt="Pick a person:"
                 shouldReloadAll=true
                 selectionBinding=selected
                 valueBinding=articleValue
    }}
<br>
<br>
Second drop down:                
    {{
         view "select"
         contentBinding=availableComment
         optionLabelPath="content.text"
         optionValuePath="content.id"
         prompt="related task:"
                 shouldReloadAll=true
                 valueBinding=articleValue
    }}
</script>

  <script src="http://ift.tt/1rfghyb"></script>
  <script src="http://ift.tt/1U7HzIj"></script>
  <script src="http://ift.tt/1EY7wOg"></script>
  <script src="http://ift.tt/1U7HzIl"></script>
  <script src="js/amit_dropdown.js"></script>
  <!-- to activate the test runner, add the "?test" query string parameter -->
  <script src="tests/runner.js"></script>
</body>
</html>



Aucun commentaire:

Enregistrer un commentaire