update files

This commit is contained in:
Nuintun 2015-11-20 17:58:30 +08:00
parent 627d176ea8
commit 9420e3613f
3 changed files with 14 additions and 15 deletions

View File

@ -22,7 +22,6 @@ module.exports = Vue.component('app-configure', {
return { return {
name: '', name: '',
path: '', path: '',
_cached: {},
submitError: '', submitError: '',
popup: false popup: false
} }

View File

@ -1,3 +1,3 @@
<label>{{label}}</label> <label>{{label}}</label>
<input type="text" :title="path" :placeholder="label" v-model="path" lazy/>&nbsp; <input type="text" :title="path" :placeholder="label" :value="path" readonly/>&nbsp;
<a title="选择项目" href="javascript:;" class="icon-ellipsis" @click="open"></a> <a title="选择项目" href="javascript:;" class="icon-ellipsis" @click="open"></a>

View File

@ -33,11 +33,21 @@ module.exports = Vue.component('dynamic-item', {
return { return {
name: '', name: '',
value: '', value: '',
_cached: {},
nameError: '', nameError: '',
valueError: '' valueError: ''
}; };
}, },
computed: {
uniqueCache: function (){
var cache = {};
this.items.forEach(function (item){
cache[item.name] = true;
}, this);
return cache;
}
},
methods: { methods: {
add: function (){ add: function (){
// trim value // trim value
@ -47,7 +57,7 @@ module.exports = Vue.component('dynamic-item', {
// name error // name error
if (!this.name) { if (!this.name) {
this.nameError = '不能为空'; this.nameError = '不能为空';
} else if (this.$data._cached[this.name]) { } else if (this.uniqueCache[this.name]) {
this.nameError = ' ' + this.name + ' 已存在'; this.nameError = ' ' + this.name + ' 已存在';
} else { } else {
this.nameError = ''; this.nameError = '';
@ -61,9 +71,7 @@ module.exports = Vue.component('dynamic-item', {
} }
// add item // add item
if (this.name && this.value && !this.$data._cached[this.name]) { if (this.name && this.value && !this.uniqueCache[this.name]) {
// cache name
this.$data._cached[this.name] = true;
// add item // add item
this.items.push({ name: this.name, value: this.value }); this.items.push({ name: this.name, value: this.value });
@ -76,10 +84,7 @@ module.exports = Vue.component('dynamic-item', {
this[key] = ''; this[key] = '';
}, },
remove: function (index){ remove: function (index){
var item = this.items[index];
this.items.splice(index, 1); this.items.splice(index, 1);
delete this.$data._cached[item.name];
} }
}, },
events: { events: {
@ -87,10 +92,5 @@ module.exports = Vue.component('dynamic-item', {
this.nameError = ''; this.nameError = '';
this.valueError = ''; this.valueError = '';
} }
},
created: function (){
this.items.forEach(function (item){
this.$data._cached[item.name] = true;
}, this);
} }
}); });