Note that there are some explanatory texts on larger screens.

plurals
  1. PObackbone view listens to model event
    primarykey
    data
    text
    <p>im having problem with backbone view-model communication, view should be listening events from model, so function couponReader is suppossed to get the data from model and add to the cart after a sort of confirmation. Any help is appreciated</p> <pre><code>define([ 'jquery', 'underscore', 'backbone', 'text!templates/menu/menu.html', 'text!templates/menu/cartItem.html', 'collections/cart', 'views/menu/topBar', 'models/coupon', 'swipe' ], function ($, _, Backbone, menuTemplate, cartItemTemplate, Cart, TopBarView, Coupon) { var slider; var sliderPosition = 0; var top; var menuView = Backbone.View.extend({ el:$("body"), events:{ "click #keno50":"addKeno50", }, initialize:function () { this.couponReader(); }, render:function () { this.el.html(menuTemplate); // TODO - Memory leak here :O new TopBarView({ el: this.$('#topBar') }).render(); this.slider = new Swipe(document.getElementById('slider'), {startSlide:sliderPosition}); this.resizeScreen(); return this; }, couponReader:function () { var coupon = new Coupon({ //problem here name: Coupon.getCoupon().name, price: Coupon.getCoupon().price }); Cart.add(coupon); }, addKeno50:function () { var keno50 = { name:"Keno", price:50 } Cart.add(keno50); sliderPosition = this.slider.getPos(); this.render(); } }); return new menuView; }); </code></pre> <p>model class: it listens to the server in loop, get data from server whenever a data is loaded.</p> <pre><code>define(['jquery', 'underscore', 'backbone'], function ($,_, Backbone) { var Coupon = Backbone.Model.extend({ initialize:function () { this.getCoupon(); //console.log("funkar*?"); }, getCoupon : function() { var XHR = this.getRequest(); XHR.done(function(data){ var keno10 = { name: data.description, price: parseInt(data.price)} var price = parseInt(data.price); var name = data.description; var status = data.ok; }) }, getRequest:function() { var fn = arguments.callee; var XHR = $.ajax({ url: '/nextdocument', type: 'GET', async: true, cache: false, timeout: 11000, //vänta på svar från servern om ingen inläsning success:function(data) { var name = data.description; var price = data.price; console.log("read--&gt; " + name + price); setTimeout(fn, 1000); if (data.ok == "true") { data["ok"] = data.ok; $.ajax( { url: "/customerdone", data: JSON.stringify(data), processData: false, type: 'POST', contentType: 'application/json' } ) }else{ //no document if no read in console.log("error--&gt; " + data.errorMessage) } } }) return XHR; } }); return Coupon; }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload