Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c2637dc6e9
Fetching contributors…

Cannot retrieve contributors at this time

file 42 lines (34 sloc) 0.933 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
Spine = require('spine')
$ = jQuery

class Stock extends Spine.Model
  @configure 'Stock', 'name', 'code', 'currentPrice'

  @extend Spine.Model.Local

  constructor: ->
    super

  @endpoint: 'http://hq.sinajs.cn/list='

  @createStockAsync: (code) ->
    return unless code
    $.mobile.showPageLoadingMsg()
    console.log "code #{code}"
    if code.charAt(0) == '6'
      valname = 'sh' + code
      url = Stock.endpoint + 'sh' + code
    else
      valname = 'sz' + code
      url = Stock.endpoint + 'sz' + code
    console.log "url #{url}"
    $.ajaxSetup
      cache: true

    $.getScript url, (data) =>
      $.ajaxSetup
        cache: false

      eval "data = hq_str_#{valname}"
      console.log "data = #{data}"
      $.mobile.hidePageLoadingMsg()
      return unless data
      vals = data.split ","
      Stock.create
        code: code
        name: vals[0]
        currentPrice: vals[3]

module.exports = Stock
Something went wrong with that request. Please try again.