显示列表项中的数组值 - Jquery,Backbone.js

时间:2013-01-25 18:00:07

标签: javascript jquery backbone.js

我试图通过使用骨干视图模型的点击输出数组值,请告知如何在单独的行上输出每个数组值,或者通过jquery在列表项中显示每个数组值。谢谢:))

<!DOCTYPE html>
<head>
<meta charset=utf-8" />
<title>Test</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="underscore.js"></script>
        <script type="text/javascript" src="backbone.js"></script>
</head>

<body>

<button>click</button>
<div class="ctype"></div>

<div class="cexperience"></div>

<script type="text/javascript">
    var Job1 = Backbone.Model.extend({
        defaults:{
        type:'permanent',   
        experience:['html','css','php']
        }

    });

    var myJob1 = new Job1();

    var Jobview1 = Backbone.View.extend({
        el:'button',
        events:{
            'click':'render'
        },
        render: function(){

            var _type = myJob1.get('type');
            var _experience = myJob1.get('experience');


            $('div.ctype').html(_type);
            $('div.cexperience').html(_experience);

            return this
        }

    })

    $(document).ready(function(e) {
            var myJobview1 = new Jobview1();

    });
    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

_.each(_experience, function (key, value) {
    var tmp = $('<p />');
    tmp.html(value);
    $('.experience').append(tmp);
)};

这应该有效。 也许你需要切换键,值到值,键。 我倾向于忘记参数的顺序。