avalon.scan()可以在一个页面多次使用吗
VM定义完成并avalon.scan()后,append方法新增了html元素,新增html代码中使用的avalon框架失效,我思考是否可以再次avalon.scan(),但是用了好像没有起作用,代码如下:
1、定义VM:
var fareDemoVm;
avalon.ready(function () {
fareDemoVm = avalon.define({
$id: 'fareDemo',
valueWay: '0',
des1Array: ['件','kg'],
des2Array: ['件','重(kg)'],
des3Array: ['满','在'],
des4Array: ['件','kg内'],
des1: '件',
des2: '件',
des3: '满',
des4: '件',
itemUnit: true,
weightUnit: false
});
avalon.scan();
fareDemoVm.$watch("valueWay", function(a){
var index = parseInt(a);
fareDemoVm.des1 = fareDemoVm.des1Array[index];
fareDemoVm.des2 = fareDemoVm.des2Array[index];
fareDemoVm.des3 = fareDemoVm.des3Array[index];
fareDemoVm.des4 = fareDemoVm.des4Array[index];
$("span.des3").text(fareDemoVm.des3);
$("span.des4").text(fareDemoVm.des4);
fareDemoVm.itemUnit = !fareDemoVm.itemUnit;
fareDemoVm.weightUnit = !fareDemoVm.weightUnit;
});
});
2、添加html代码后扫描(使用的laytpl.js)
function plusFreePost() {
freePostCount++;
var data = {
count : freePostCount,
des3 : fareDemoVm.des3,
des4 : fareDemoVm.des4,
weightUnit : fareDemoVm.weightUnit,
itemUnit : fareDemoVm.itemUnit
}
var $code_snippet = $("#freePostPlus").html();
var _html = laytpl($code_snippet).render(data);
$("#specifyFreefee table tbody").append(_html);
avalon.scan(); ******************************并没有扫描
}
请老师指点下