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
最新版本bug #1566
Comments
多次点击切换出现 |
不行啊,你这样会重复定义vm |
你的vm不要放在事件里面加载 |
但上几个版本都没问题啊 |
不行,最开始你就违背重复定义的标准 |
requirejs 不是只加载了一次吗? vm还会重复定义? |
我现在单页应用就是通过url改变事件来加载不同模块的 那不同模块的vm我该写在哪? |
1.js再拆成2个,2.js也拆成两个. 一些JS只定VM,一些JS做业务 ,一开始把所有定义VM的JS全部加载好。然后在路由的回调或点击事件中,再慢慢加载业务逻辑JS及对应的页面模板 |
不过,建议你还是用我的路由器例子改吧,ms-html加载ms-controller,我还没有想好 |
1.不同模块的vm不能按需加载吗?
|
你的路由器例子是把每个单页都做成了一个组件,以后组件里必然还要嵌套小组件,感觉有点复杂,可我想的是只是加载模板,没必要把每张页面都做成组件,组件只是作为一些高复用的小部件被模板所使用 这是你以前写的例子 也是定义在模块里的
|
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Drag-Drop</title>
<script src="../dist/avalon.js"></script>
<script>
function heredoc(fn) {
return fn.toString().replace(/^[^\/]+\/\*!?\s?/, '').
replace(/\*\/[^\/]+$/, '').trim().replace(/>\s*</g, '><')
}
var v123 = heredoc(function () {
/*
<div ms-controller="test2">
<p>123</p>
<xmp cached="true" ms-widget="{is:'ms-span'}"></xmp>
</div>
*/
})
var v456 = heredoc(function () {
/*
<div ms-controller="test3">
<p>456</p>
<xmp cached="true" ms-widget="{is:'ms-span'}"></xmp>
</div>
*/
})
</script>
<script>
var vm = avalon.define({
$id: 'test',
tpl: "",
switch1: function () {
setTimeout(function () {
console.log('111111')
avalon.vmodels.test.tpl = v123
})
},
switch2: function () {
setTimeout(function () {
console.log('sssss')
avalon.vmodels.test.tpl = v456
})
}
});
var vm2 = avalon.define({
$id: 'test2',
ddd: 111
});
var vm3 = avalon.define({
$id: 'test3',
ddd: 222
});
avalon.component('ms-span', {
template: "<span>{{@ddd}}</span>",
defaults: {
ddd:'3333'
}
});
</script>
</head>
<body ms-controller="test">
<div ms-html="@tpl"></div>
<button ms-click="@switch1">切换1</button>
<button ms-click="@switch2">切换2</button>
</body>
</html> |
又改了改,但那个ms-html动态设置ns-controller的case 需要多少测试与调校 |
组件搞成这样,性能就最高了 |
用注释存储模板的话 自动化构建时还要特别处理下 |
新版本还是有问题 多次切换后点击事件依旧失效 而且vm我已经预先定义好了 这次没有动态加载vm 而且我觉得requirejs 只会动态加载一次vm 不会动态重复定义vm吧?
1.js
123.html
2.js
456.html
|
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Drag-Drop</title>
<script src="../dist/avalon.js"></script>
<script>
function heredoc(fn) {
return fn.toString().replace(/^[^\/]+\/\*!?\s?/, '').
replace(/\*\/[^\/]+$/, '').trim().replace(/>\s*</g, '><')
}
var v123 = heredoc(function () {
/*
<div ms-controller="test2">
<p ms-click="@alert">123</p>
<xmp cached='true' ms-widget="{is:'ms-span',$id:'yyy'}"></xmp>
</div>
*/
})
var v456 = heredoc(function () {
/*
<div ms-controller="test3">
<p ms-click="@alert">456</p>
<xmp cached='true' ms-widget="{is:'ms-span',$id:'xxx'}"></xmp>
</div>
*/
})
</script>
<script>
var vm = avalon.define({
$id: 'test',
tpl: "",
switch1: function () {
setTimeout(function () {
console.log('111111')
avalon.vmodels.test.tpl = v123
})
},
switch2: function () {
setTimeout(function () {
console.log('sssss')
avalon.vmodels.test.tpl = v456
})
}
});
var vm2 = avalon.define({
$id: 'test2',
ddd: 111,
alert: function(){
console.log('????')
}
});
var vm3 = avalon.define({
$id: 'test3',
ddd: 222,
alert: function(){
console.log('!!!!')
}
});
avalon.component('ms-span', {
template: "<span>{{@ddd}}</span>",
defaults: {
ddd:'3333'
}
});
</script>
</head>
<body ms-controller="test">
<div ms-html="@tpl"></div>
<button ms-click="@switch1">切换1</button>
<button ms-click="@switch2">切换2</button>
</body>
</html> |
我试过是好的,你更新一下,看一下时间 |
用最新版本 每个切换按钮第一次都可以 多次点击后里面组件的alert失效
|
加个cached=true |
终于搞定了 多谢 |
html TypeError: Cannot set property 'textContent' of undefined(…) TypeError: Cannot set property 'textContent' of undefined
at Function.avalon.clearHTML (http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:2558:23)
at avalon.directive.update (http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:3705:17)
at module.exports (http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:3362:10)
at Object.avalon.directive.diff (http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:3697:14)
at http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:7441:39
at RegExp.Symbol.replace
at String.replace (native)
at diffProps (http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:7436:19)
at diff (http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:7404:22)
at diff (http://127.0.0.1:8020/systems/vendor/avalon/avalon.js:7407:22) diffProps error
1.js
123.html
2.js
456.html
The text was updated successfully, but these errors were encountered: