Ecco qualcosa come ho passati attraverso questo. Basta copiare e incollare esempi di lavoro al di sotto
<body>
<div rv-each-book="model.books">
<button rv-on-click="model.selectedBook | args book">
Read the book {book}
</button>
</div>
</body>
<script type="text/javascript">
rivets.formatters["args"] = function (fn) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
return fn.apply(null, args);
};
};
rvBinder = rivets.bind(document.body, {
model: {
selectedBook: function (book) {
alert("Selected book is " + book);
},
books: ["Asp.Net", "Javascript"]
}
});
</script>
o un approccio alternativo è vincolante evento
<body>
<div rv-each-book="books">
<a rv-cust-href="book">
Read the book {book}
</a>
</div>
</body>
<script type="text/javascript">
rivets.binders['cust-href'] = function (el, value) {
//el.href = '/Books/Find/' + value;
//OR
el.onclick = function() { alert(value); };
}
rvBinder = rivets.bind(document.body, {
books: ["Asp.Net", "Javascript"]
});
</script>
'RV-on-clic = "abc ({} cosa)"' http://rivetsjs.com/docs/reference/# on- [event] È necessario leggere il binding bidirezionale e utilizzare la documentazione della libreria di binding. – Pogrindis
No. L'ho sicuramente provato, e non funziona. Fornisce questo errore: Uncaught TypeError: this.call non è una funzione/t.public.handler @ rivets.bundled.min.js: 6/t.Binding.e.eventHandler @ rivets.bundled.min.js: 6/n .event.dispatch @ jquery-2.1.4.min.js: 3/n.event.add.r.handle @ jquery-2.1.4.min.js: 3 – paulwal222
L'unica soluzione funzionante che ho trovato utilizza una funzione che è un membro di {thing}, che mi sembra ridicolo. Quindi: 'rv-on-click =" cosa.my_funzione "' – paulwal222