2

I made and initialized my model with the "change:status" event like this

Box = Backbone.Model.extend({
    initialize: function() {
      this.on('change:status', this.changed, this);
    },
    changed: function() {
      $('.changed').text('I changed'); // Testing if the 'change:status' is fired
    }
});

My Box collections is setup this way

BoxList = Backbone.Collection.extend({
    model: Box,
    initialize: function() {
       this.on('add', this.addOne, this);
       socket.on('box-status-change', this.boxStatusChanged, this);
    },
    boxStatusChanged: function(box) {
        Boxes.each(function(model) {
          if(model.get('changed') == box.changed) {
            model.set({status: 'changed'});
          }
        });
    },
    addOne: function.... // Some code removed
});

Boxes = new BoxList();

Checking in Chromes web developer tools, the attribute status was set to changed properly but an error Uncaught TypeError: Object #<Object> has no method 'apply' occured. The change:title event of the model was not fired. Is there something I miss when adding the event to the model?

By the way, I'm using the backbone-iosync.js for the Backbone.sync method...


Can JSTL transform XML encoded in UTF-8?

I am making a simple JSP application to transform XML data into HTML. I use JSTL and my XML data is encoded in UTF-8. It works, but the danish characters look strange in the browser.

Like this:

Danish characters written directly in jsp: ÆØÅ æøå
Same danish characters transformed with jstl:
character: Æ character: æ
character: Ø character: ø
character: Å character: å

However, if I manually change the xml definition like so:

<?xml version="1.0" encoding="ISO-8859-1" ?>

The output is transformed properly.

Should I set up JSTL in some way to handle UTF-8, or is it,that my file is actually latin1 encoded by mistake? I do not know how to check this...

Here is my test xml file:

    <?xml version="1.0" encoding="UTF-8" ?>
<rows>
<row>
    <name>character: Æ</name>
    <surname>character: æ</surname>
</row>
<row>
    <name>character: Ø</name>
    <surname>character: ø</surname>
</row>
<row>
    <name>character: Å</name>
    <surname>character: å</surname>
</row>
</rows>

Here is my xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <table border="0">
        <xsl:for-each select="rows/row">
            <tr>
                <td>
                    <xsl:value-of select="name" />
                </td>
                <td>
                    <xsl:value-of select="surname" />
                </td>
            </tr>
        </xsl:for-each>
    </table>
</xsl:template>
</xsl:stylesheet>

My index.jsp:

<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org  /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
Written directly in jsp: ÆØÅ æøå
<h3>xml transformed with jstl:</h3>
<c:import url="/Test.xsl" var="xsltdoc" />
<c:import url="/Test.xml" var="xmldoc" />
<x:transform xml="${xmldoc}" xslt="${xsltdoc}" />
</body>
</html>

I am using JSTL libraries (Implementation-Version: 1.2) on JBOSS AP 4.2.3.

4

1 回答 1

4

Backbone uses an internal attribute called changed on models:

http://backbonejs.org/#Model-changed

changed model.changed
The changed property is the internal hash containing all the attributes that have changed since the last "change" event was triggered. Please do not update changed directly. Its state is maintained internally by set and change. A copy of changed can be acquired from changedAttributes.

Rename your callback to something else and that works

Box = Backbone.Model.extend({
    initialize: function() {
      this.on('change:status', this.changedState, this);
    },
    changedState: function() {
      console.log('changed');
    }
});

A Fiddle to reproduce your problem http://jsfiddle.net/NrTPk/ and a modified version http://jsfiddle.net/NrTPk/1/

于 2012-08-21T10:11:58.330 回答