使用JQuery绑定mvvm数据源
我有以下建议:使用JQuery绑定mvvm数据源,jquery,data-binding,kendo-ui,datasource,Jquery,Data Binding,Kendo Ui,Datasource,我有以下建议: <div class="container" data-bind="source: content" data-template="content-template"></div> 在JS中,我希望动态添加更多的DIV(更好:克隆.container DIV),并将数据绑定源更改为content2、content3 基本上我想要这个:$(.question.clone2”).data(“source”,content2) 正确的语法是什么?试试这个:
<div class="container" data-bind="source: content" data-template="content-template"></div>
在JS中,我希望动态添加更多的DIV(更好:克隆.container DIV),并将数据绑定源更改为content2、content3
基本上我想要这个:$(.question.clone2”).data(“source”,content2)
正确的语法是什么?试试这个:
var clone = $('.container').clone(); // use .first() if there are more then one .container class
$(clone).data("source", "content2");
$(文档).ready(函数(){
var clone=$('.container').first().clone();//克隆第一个容器div
(clone).insertAfter('.container');//在最后一个容器div之后插入克隆
var length=$('.container').length;//获取有多少个容器div
$('.container').last().attr('data-bind','source:content“+length+”);//更改last container div数据绑定值(以自动递增的方式,如content2、content3等)
});代码>
.container{
浮动:左;
宽度:40%;
高度:200px;
背景:灰色;
填充:10px;
利润率:20px;
}