Knockout JS Ajax call not populating observable array

后端 未结 1 578
萌比男神i
萌比男神i 2021-01-23 05:53

The below example shows an observable array being populated from with Json, which then allows you to filter the results into 2 lists based on \'type\'.

This all works fi

相关标签:
1条回答
  • 2021-01-23 06:24

    You are replacing the variable, not updating it:

    ...
    success: function(data) {
      self.dimensions = data
    },
    ...
    

    Observables are updated this way:

    ...
    success: function(data) {
      self.dimensions(data)
    },
    ...
    

    I wouldn't use filteredDimensions('AREA') because this gets call as soon as your page is rendered. Use observables, store in a variable currentFilter the value and then through a template load the proper view. Also, if you only have two filters, a better approach is just to have two methods: filterByArea and filterByBrand.

    EDIT: Added example: http://jsfiddle.net/jjperezaguinaga/spdKE/4/

    0 讨论(0)
提交回复
热议问题