Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User's return null on option tag #1338

Closed
beratn opened this issue Apr 19, 2017 · 3 comments
Closed

User's return null on option tag #1338

beratn opened this issue Apr 19, 2017 · 3 comments

Comments

@beratn
Copy link

beratn commented Apr 19, 2017

I'm trying list my data to select's options.I'm using handlebars backbone jquery requireJS.

userselectlist.js

var users = new UserCollection();
var SelectUserList = Backbone.View.extend({
    model: User,
    el:'.page',
    render:function(users)  {
        var template = Handlebars.compile(SelectUserListTemplate);
        var html = template({users:users.toJSON()});
        console.log(users);//This line
       $("#userSelect").html(html);
    }
});

return {
    users:users,
    SelectUserList:SelectUserList
};

my select-user-list.html

 <option value="">Kullanıcı Seçiniz</option>
{{#each users}}
<option value='{{userID}}'>{{firstName}}</option>
{{/each}}

index.html

<div class="page">
            <div class="form-group">
                <select class="form-control" id="userSelect"></select>
            </div>

router.js

user:function(){
  $('body').after(spinner.spin().el);
        var users = new Users();
        var userSelect = new UserSelectList.SelectUserList();
        users.fetch({

            contentType: "application/json",
            cache: false,
            success: function (m_users) {
                m_users.each(function (m_model) {
                    spinner.stop();
                    var userList = new UserSelectList.SelectUserList();
                    UserSelectList.users = new Users();
                    userList.render(m_model);
                });
            }

My problem is user's printing with console.log .But select tag has a null option line.If you don't understand(sorry of my english) , you can look this ScreenShot

http://pasteboard.co/6knbWGzMi.png

@joshuaedwardcrowe
Copy link

What is {users:users.toJSON()}? Shouldn't it be users.users.toJSON() or JSON.parse(users.users)?

@nknapp
Copy link
Collaborator

nknapp commented May 13, 2017

@berat703 Please add a comment if you issue is still open. It seems to me that it is answered, so I'm closing it now.

@nknapp nknapp closed this as completed May 13, 2017
@nknapp
Copy link
Collaborator

nknapp commented May 13, 2017

Thanks for answering @Crowes. I have decided to act as a Collaborator here, because there seems to be a lack of them and I like the project. But it is nice to see that there are other people helping out as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants