0

我正在尝试使用主干视图模型通过单击输出数组值,请告知如何在单独的行上输出每个数组值,或者可能通过 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>
4

1 回答 1

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

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

于 2013-01-25T18:05:16.827 回答