我正在尝试使用Ractive.js将项添加到数组中。这就是我的......
<select value='{{selectedColumn}}'>
{{#colNames}}
<option value='{{this}}'>{{this}}</option>
{{/colNames}}
</select>
<select value='{{selectedLogic}}'>
{{#possibleLogic}}
<option value='{{this}}'>{{this}}</option>
{{/possibleLogic}}
</select>
<input value='{{searchVal}}'>
<button on-click='addFilter(selectedColumn, selectedLogic, searchVal)'>Add filter</button>
在Ractive对象中......
filterList = new Ractive({
el: 'container',
template: '#template',
data: {
items: myItems,
},
addFilter: function (cat, log, val) {
console.log("yo");
items.push({
description: cat + " " + log + " " + val,
completed: false
});
}
});
还尝试使用按钮调用此功能......
filterList.on({
new_filter: function ( cat, log, val ) {
console.log("hello");
items.push({
description: cat + " " + log + " " + val,
completed: false
});
},
});
这两种方法似乎都不起作用。 console.log()甚至不会被调用。
由于
答案 0 :(得分:0)
花了一点时间,这似乎有效,但也许这不是最好的解决方案......
filterList.on('testFunc', function(){
var tmp = (this.get("selectedColumn") + " " + this.get("selectedLogic") + " " + this.get("searchVal"))
items.push({description: tmp, completed: false})
});
和按钮的代码......
<button on-click='testFunc'>Add filter</button>